@@ -30,12 +30,89 @@ public function test_pagination_correctly_handles_paginated_results()
3030 $ model ->shouldReceive ('searchableUsing ' )->andReturn ($ engine = m::mock ());
3131
3232 $ engine ->shouldReceive ('paginate ' );
33- $ engine ->shouldReceive ('map ' )->andReturn ($ results = Collection::make ([new stdClass ]));
34- $ engine ->shouldReceive ('getTotalCount ' );
33+ $ engine ->shouldReceive ('map ' )->andReturn ($ results = Collection::times (15 , function () {
34+ return new stdClass ;
35+ }));
36+ $ engine ->shouldReceive ('getTotalCount ' )->andReturn (16 );
3537
3638 $ model ->shouldReceive ('newCollection ' )->andReturn ($ results );
3739
38- $ builder ->paginate ();
40+ $ paginated = $ builder ->paginate ();
41+
42+ $ this ->assertSame ($ results ->all (), $ paginated ->items ());
43+ $ this ->assertSame (16 , $ paginated ->total ());
44+ $ this ->assertSame (15 , $ paginated ->perPage ());
45+ $ this ->assertSame (1 , $ paginated ->currentPage ());
46+ $ this ->assertSame ([
47+ 'path ' => 'http://localhost/foo ' ,
48+ 'pageName ' => 'page ' ,
49+ ], $ paginated ->getOptions ());
50+ }
51+
52+ public function test_simple_pagination_correctly_handles_paginated_results ()
53+ {
54+ Paginator::currentPageResolver (function () {
55+ return 1 ;
56+ });
57+ Paginator::currentPathResolver (function () {
58+ return 'http://localhost/foo ' ;
59+ });
60+
61+ $ builder = new Builder ($ model = m::mock (), 'zonda ' );
62+ $ model ->shouldReceive ('getPerPage ' )->andReturn (15 );
63+ $ model ->shouldReceive ('searchableUsing ' )->andReturn ($ engine = m::mock ());
64+
65+ $ engine ->shouldReceive ('paginate ' );
66+ $ engine ->shouldReceive ('map ' )->andReturn ($ results = Collection::times (15 , function () {
67+ return new stdClass ;
68+ }));
69+ $ engine ->shouldReceive ('getTotalCount ' )->andReturn (16 );
70+
71+ $ model ->shouldReceive ('newCollection ' )->andReturn ($ results );
72+
73+ $ paginated = $ builder ->simplePaginate ();
74+
75+ $ this ->assertSame ($ results ->all (), $ paginated ->items ());
76+ $ this ->assertTrue ($ paginated ->hasMorePages ());
77+ $ this ->assertSame (15 , $ paginated ->perPage ());
78+ $ this ->assertSame (1 , $ paginated ->currentPage ());
79+ $ this ->assertSame ([
80+ 'path ' => 'http://localhost/foo ' ,
81+ 'pageName ' => 'page ' ,
82+ ], $ paginated ->getOptions ());
83+ }
84+
85+ public function test_simple_pagination_correctly_handles_paginated_results_without_more_pages ()
86+ {
87+ Paginator::currentPageResolver (function () {
88+ return 1 ;
89+ });
90+ Paginator::currentPathResolver (function () {
91+ return 'http://localhost/foo ' ;
92+ });
93+
94+ $ builder = new Builder ($ model = m::mock (), 'zonda ' );
95+ $ model ->shouldReceive ('getPerPage ' )->andReturn (15 );
96+ $ model ->shouldReceive ('searchableUsing ' )->andReturn ($ engine = m::mock ());
97+
98+ $ engine ->shouldReceive ('paginate ' );
99+ $ engine ->shouldReceive ('map ' )->andReturn ($ results = Collection::times (10 , function () {
100+ return new stdClass ;
101+ }));
102+ $ engine ->shouldReceive ('getTotalCount ' )->andReturn (10 );
103+
104+ $ model ->shouldReceive ('newCollection ' )->andReturn ($ results );
105+
106+ $ paginated = $ builder ->simplePaginate ();
107+
108+ $ this ->assertSame ($ results ->all (), $ paginated ->items ());
109+ $ this ->assertFalse ($ paginated ->hasMorePages ());
110+ $ this ->assertSame (15 , $ paginated ->perPage ());
111+ $ this ->assertSame (1 , $ paginated ->currentPage ());
112+ $ this ->assertSame ([
113+ 'path ' => 'http://localhost/foo ' ,
114+ 'pageName ' => 'page ' ,
115+ ], $ paginated ->getOptions ());
39116 }
40117
41118 public function test_macroable ()
0 commit comments