diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java index bf2ca7fc5904..2ba1abf9515f 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java @@ -176,6 +176,7 @@ public PaginatedArrayList pull(String query, int offset,int limit, S ret.add(new ContentMap(cc,user,EDIT_OR_PREVIEW_MODE,currentHost,context)); } ret.setQuery(cons.getQuery()); + ret.setTotalResults(cons.getTotalResults()); return ret; } catch(Throwable ex) { diff --git a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java index 1c90ada12af3..11305e3fe92a 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java @@ -38,6 +38,7 @@ import com.dotmarketing.portlets.languagesmanager.model.Language; import com.dotmarketing.portlets.structure.model.Relationship; import com.dotmarketing.util.PageMode; +import com.dotmarketing.util.PaginatedArrayList; import com.dotmarketing.util.PaginatedContentList; import com.dotmarketing.util.WebKeys.Relationship.RELATIONSHIP_CARDINALITY; import com.liferay.portal.model.User; @@ -53,6 +54,7 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.IntStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.velocity.context.Context; @@ -880,4 +882,27 @@ public void testPullRelated_MultiLangContent() throws DotDataException, DotSecur } + + /** + * Method to Test: {@link ContentTool#pull(String, int, int, String)}} + * When: pulling content and having more than one content + * Should: Return the total under the key "totalResults" + * + */ + @Test + public void testPull_includeTotal() { + final ContentType blogLikeType = TestDataUtils.getBlogLikeContentType(); + + final ContentletDataGen contentletDataGen = new ContentletDataGen(blogLikeType.inode()).host(defaultHost); + IntStream.range(0, 10).forEach(i -> contentletDataGen.nextPersisted()); + + final ContentTool contentTool = getContentTool(defaultLanguage.getId()); + + final PaginatedArrayList results = contentTool.pull( + "+contentType:" + blogLikeType.variable(), 0, 0, + "modDate desc" + ); + + Assert.assertEquals(10, results.getTotalResults()); + } }