| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851 |
- <?php
- /**
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://cakephp.org CakePHP(tm) Project
- * @since 1.2.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\View\Helper;
- use Cake\Core\Configure;
- use Cake\Http\ServerRequest;
- use Cake\I18n\I18n;
- use Cake\Routing\Router;
- use Cake\TestSuite\TestCase;
- use Cake\View\Helper\PaginatorHelper;
- use Cake\View\View;
- /**
- * PaginatorHelperTest class
- */
- class PaginatorHelperTest extends TestCase
- {
- /**
- * @var string
- */
- protected $locale;
- /**
- * @var \Cake\View\View
- */
- protected $View;
- /**
- * @var \Cake\View\Helper\PaginatorHelper
- */
- protected $Paginator;
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp()
- {
- parent::setUp();
- Configure::write('Config.language', 'eng');
- $this->View = new View();
- $this->Paginator = new PaginatorHelper($this->View);
- $this->Paginator->request = new ServerRequest();
- $this->Paginator->request->addParams([
- 'paging' => [
- 'Article' => [
- 'page' => 1,
- 'current' => 9,
- 'count' => 62,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 7,
- 'sort' => null,
- 'direction' => null,
- 'limit' => null,
- ]
- ]
- ]);
- Router::reload();
- Router::connect('/:controller/:action/*');
- Router::connect('/:plugin/:controller/:action/*');
- $this->locale = I18n::locale();
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown()
- {
- parent::tearDown();
- unset($this->View, $this->Paginator);
- I18n::locale($this->locale);
- }
- /**
- * Test the templates method.
- *
- * @return void
- */
- public function testTemplates()
- {
- $result = $this->Paginator->templates([
- 'test' => 'val'
- ]);
- $this->assertSame(
- $this->Paginator,
- $result,
- 'Setting should return the same object'
- );
- $result = $this->Paginator->templates();
- $this->assertArrayHasKey('test', $result);
- $this->assertEquals('val', $result['test']);
- $this->assertEquals('val', $this->Paginator->templates('test'));
- }
- /**
- * testHasPrevious method
- *
- * @return void
- */
- public function testHasPrevious()
- {
- $this->assertFalse($this->Paginator->hasPrev());
- $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
- $this->assertTrue($this->Paginator->hasPrev());
- $this->Paginator->request->params['paging']['Article']['prevPage'] = false;
- }
- /**
- * testHasNext method
- *
- * @return void
- */
- public function testHasNext()
- {
- $this->assertTrue($this->Paginator->hasNext());
- $this->Paginator->request->params['paging']['Article']['nextPage'] = false;
- $this->assertFalse($this->Paginator->hasNext());
- $this->Paginator->request->params['paging']['Article']['nextPage'] = true;
- }
- /**
- * testSortLinks method
- *
- * @return void
- */
- public function testSortLinks()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
- ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->options(['url' => ['param']]);
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'current' => 9,
- 'count' => 62,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 7,
- 'sort' => 'date',
- 'direction' => 'asc',
- 'page' => 1,
- ]
- ];
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', null, ['model' => 'Nope']);
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', null, ['model' => 'Article']);
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('date');
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=date&direction=desc', 'class' => 'asc'],
- 'Date',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', 'TestTitle');
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc'],
- 'TestTitle',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc'],
- 'ascending',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
- $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc', 'class' => 'asc'],
- 'descending',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc', 'class' => 'desc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc', 'class' => 'asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('title', 'Title', ['direction' => 'desc']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc', 'class' => 'desc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('title', 'Title', ['direction' => 'ASC']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=asc', 'class' => 'desc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('title', 'Title', ['direction' => 'asc']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc', 'class' => 'asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('title', 'Title', ['direction' => 'desc']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc', 'class' => 'asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test sort() with escape option
- */
- public function testSortEscape()
- {
- $result = $this->Paginator->sort('title', 'TestTitle >');
- $expected = [
- 'a' => ['href' => '/index?sort=title&direction=asc'],
- 'TestTitle >',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => true]);
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => false]);
- $expected = [
- 'a' => ['href' => '/index?sort=title&direction=asc'],
- 'TestTitle >',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test that sort() works with virtual field order options.
- *
- * @return void
- */
- public function testSortLinkWithVirtualField()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'form' => [], 'url' => ['url' => 'accounts/']],
- ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'full_name';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('Article.full_name');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=Article.full_name&direction=desc', 'class' => 'asc'],
- 'Article Full Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('full_name');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=full_name&direction=desc', 'class' => 'asc'],
- 'Full Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'full_name';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('Article.full_name');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=Article.full_name&direction=asc', 'class' => 'desc'],
- 'Article Full Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('full_name');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=full_name&direction=asc', 'class' => 'desc'],
- 'Full Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testSortLinksUsingDirectionOption method
- *
- * @return void
- */
- public function testSortLinksUsingDirectionOption()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index',
- 'url' => ['url' => 'accounts/', 'mod_rewrite' => 'true']],
- ['base' => '/', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->options(['url' => ['param']]);
- $result = $this->Paginator->sort('title', 'TestTitle', ['direction' => 'desc']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc'],
- 'TestTitle',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending'], ['direction' => 'desc']);
- $expected = [
- 'a' => ['href' => '/accounts/index/param?sort=title&direction=desc'],
- 'descending',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testSortLinksUsingDotNotation method
- *
- * @return void
- */
- public function testSortLinksUsingDotNotation()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
- ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('Article.title');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=Article.title&direction=asc', 'class' => 'desc'],
- 'Article Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sort('Article.title', 'Title');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=Article.title&direction=asc', 'class' => 'desc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('Article.title', 'Title');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=Article.title&direction=desc', 'class' => 'asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Account.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/accounts/index?sort=title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test multiple pagination sort links
- *
- * @return void
- */
- public function testSortLinksMultiplePagination()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
- ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->options(['model' => 'Articles']);
- $this->Paginator->request['paging'] = [
- 'Articles' => [
- 'current' => 9,
- 'count' => 62,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 7,
- 'sort' => 'date',
- 'direction' => 'asc',
- 'page' => 1,
- 'scope' => 'article',
- ],
- 'Tags' => [
- 'current' => 1,
- 'count' => 100,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- 'sort' => 'tag',
- 'direction' => 'asc',
- 'page' => 1,
- 'scope' => 'tags',
- ]
- ];
- $result = $this->Paginator->sort('title', 'Title', ['model' => 'Articles']);
- $expected = [
- 'a' => ['href' => '/accounts/index?article%5Bsort%5D=title&article%5Bdirection%5D=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('tag', 'Tag', ['model' => 'Tags']);
- $expected = [
- 'a' => ['class' => 'asc', 'href' => '/accounts/index?tags%5Bsort%5D=tag&tags%5Bdirection%5D=desc'],
- 'Tag',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test creating paging links for missing models.
- *
- * @return void
- */
- public function testPagingLinksMissingModel()
- {
- $result = $this->Paginator->sort('title', 'Title', ['model' => 'Missing']);
- $expected = [
- 'a' => ['href' => '/index?sort=title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next', ['model' => 'Missing']);
- $expected = [
- 'li' => ['class' => 'next disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('Prev', ['model' => 'Missing']);
- $expected = [
- 'li' => ['class' => 'prev disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- 'Prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testSortKey method
- *
- * @return void
- */
- public function testSortKey()
- {
- $result = $this->Paginator->sortKey('Article', ['sort' => 'Article.title']);
- $this->assertEquals('Article.title', $result);
- $result = $this->Paginator->sortKey('Article', ['sort' => 'Article']);
- $this->assertEquals('Article', $result);
- }
- /**
- * Test that sortKey falls back to the default sorting options set
- * in the $params which are the default pagination options.
- *
- * @return void
- */
- public function testSortKeyFallbackToParams()
- {
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
- $result = $this->Paginator->sortKey();
- $this->assertEquals('Article.body', $result);
- $result = $this->Paginator->sortKey('Article');
- $this->assertEquals('Article.body', $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
- $this->Paginator->request->params['paging']['Article']['order'] = 'DESC';
- $result = $this->Paginator->sortKey();
- $this->assertEquals('Article.body', $result);
- $result = $this->Paginator->sortKey('Article');
- $this->assertEquals('Article.body', $result);
- }
- /**
- * testSortDir method
- *
- * @return void
- */
- public function testSortDir()
- {
- $result = $this->Paginator->sortDir();
- $expected = 'asc';
- $this->assertEquals($expected, $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('desc', $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('asc', $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('desc', $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('asc', $result);
- unset($this->Paginator->request->params['paging']['Article']['direction']);
- $result = $this->Paginator->sortDir('Article', ['direction' => 'asc']);
- $this->assertEquals('asc', $result);
- $result = $this->Paginator->sortDir('Article', ['direction' => 'desc']);
- $this->assertEquals('desc', $result);
- $result = $this->Paginator->sortDir('Article', ['direction' => 'asc']);
- $this->assertEquals('asc', $result);
- }
- /**
- * Test that sortDir falls back to the default sorting options set
- * in the $params which are the default pagination options.
- *
- * @return void
- */
- public function testSortDirFallbackToParams()
- {
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('asc', $result);
- $result = $this->Paginator->sortDir('Article');
- $this->assertEquals('asc', $result);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'DESC';
- $result = $this->Paginator->sortDir();
- $this->assertEquals('desc', $result);
- $result = $this->Paginator->sortDir('Article');
- $this->assertEquals('desc', $result);
- }
- /**
- * testSortAdminLinks method
- *
- * @return void
- */
- public function testSortAdminLinks()
- {
- Configure::write('Routing.prefixes', ['admin']);
- Router::reload();
- Router::connect('/admin/:controller/:action/*', ['prefix' => 'admin']);
- Router::setRequestInfo([
- ['controller' => 'users', 'plugin' => null, 'action' => 'index', 'prefix' => 'admin'],
- ['base' => '', 'here' => '/admin/users', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['page'] = 1;
- $result = $this->Paginator->next('Next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/admin/users/index?page=2', 'rel' => 'next'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->options(['url' => ['param']]);
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/admin/users/index/param?sort=title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->options(['url' => ['param']]);
- $result = $this->Paginator->sort('Article.title', 'Title');
- $expected = [
- 'a' => ['href' => '/admin/users/index/param?sort=Article.title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that generated URLs work without sort defined within the request
- *
- * @return void
- */
- public function testDefaultSortAndNoSort()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
- ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => 1, 'current' => 3, 'count' => 13,
- 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
- 'sortDefault' => 'Article.title', 'directionDefault' => 'ASC',
- 'sort' => null
- ]
- ];
- $result = $this->Paginator->next('Next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['rel' => 'next', 'href' => '/articles/index?page=2'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testUrlGeneration method
- *
- * @return void
- */
- public function testUrlGeneration()
- {
- $result = $this->Paginator->sort('controller');
- $expected = [
- 'a' => ['href' => '/index?sort=controller&direction=asc'],
- 'Controller',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->generateUrl();
- $this->assertEquals('/index', $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 2;
- $result = $this->Paginator->generateUrl();
- $this->assertEquals('/index?page=2', $result);
- $options = ['sort' => 'Article', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options);
- $this->assertEquals('/index?page=2&sort=Article&direction=desc', $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $options = ['sort' => 'Article.name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options);
- $this->assertEquals('/index?page=3&sort=Article.name&direction=desc', $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $options = ['sort' => 'Article.name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options, null, ['escape' => false]);
- $this->assertEquals('/index?page=3&sort=Article.name&direction=desc', $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $options = ['sort' => 'Article.name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options, null, ['fullBase' => true]);
- $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
- // @deprecated 3.3.5 Use fullBase array option instead.
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $options = ['sort' => 'Article.name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options, null, true);
- $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
- }
- /**
- * test URL generation with prefix routes
- *
- * @return void
- */
- public function testGenerateUrlWithPrefixes()
- {
- Configure::write('Routing.prefixes', ['members']);
- Router::reload();
- Router::connect('/members/:controller/:action/*', ['prefix' => 'members']);
- Router::connect('/:controller/:action/*');
- Router::setRequestInfo([
- ['controller' => 'posts', 'action' => 'index', 'plugin' => null],
- ['base' => '', 'here' => 'posts/index', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['page'] = 2;
- $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
- $options = ['prefix' => 'members'];
- $result = $this->Paginator->generateUrl($options);
- $expected = '/members/posts/index?page=2';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->sort('name', null, ['url' => $options]);
- $expected = [
- 'a' => ['href' => '/members/posts/index?page=2&sort=name&direction=asc'],
- 'Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('next', ['url' => $options]);
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/members/posts/index?page=3', 'rel' => 'next'],
- 'next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('prev', ['url' => $options]);
- $expected = [
- 'li' => ['class' => 'prev'],
- 'a' => ['href' => '/members/posts/index', 'rel' => 'prev'],
- 'prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $options = ['prefix' => 'members', 'controller' => 'posts', 'sort' => 'name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options);
- $expected = '/members/posts/index?page=2&sort=name&direction=desc';
- $this->assertEquals($expected, $result);
- $options = ['controller' => 'posts', 'sort' => 'Article.name', 'direction' => 'desc'];
- $result = $this->Paginator->generateUrl($options);
- $expected = '/posts/index?page=2&sort=Article.name&direction=desc';
- $this->assertEquals($expected, $result);
- }
- /**
- * test generateUrl with multiple pagination
- *
- * @return void
- */
- public function testGenerateUrlMultiplePagination()
- {
- Router::setRequestInfo([
- ['controller' => 'posts', 'action' => 'index', 'plugin' => null],
- ['base' => '', 'here' => 'posts/index', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['scope'] = 'article';
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
- $this->Paginator->options(['model' => 'Article']);
- $result = $this->Paginator->generateUrl([]);
- $expected = '/posts/index?article%5Bpage%5D=3';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->sort('name');
- $expected = [
- 'a' => ['href' => '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name&article%5Bdirection%5D=asc'],
- 'Name',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/posts/index?article%5Bpage%5D=4', 'rel' => 'next'],
- 'next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('prev');
- $expected = [
- 'li' => ['class' => 'prev'],
- 'a' => ['href' => '/posts/index?article%5Bpage%5D=2', 'rel' => 'prev'],
- 'prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->generateUrl(['sort' => 'name']);
- $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name';
- $this->assertEquals($expected, $result);
- }
- /**
- * test generateUrl with multiple pagination and query string values
- *
- * @return void
- */
- public function testGenerateUrlMultiplePaginationQueryStringData()
- {
- Router::setRequestInfo([
- ['controller' => 'posts', 'action' => 'index', 'plugin' => null],
- ['base' => '', 'here' => 'posts/index', 'webroot' => '/']
- ]);
- $this->View->request->params['paging']['Article']['scope'] = 'article';
- $this->View->request->params['paging']['Article']['page'] = 3;
- $this->View->request->params['paging']['Article']['prevPage'] = true;
- $this->View->request->query = [
- 'article' => [
- 'puppy' => 'no'
- ]
- ];
- // Need to run __construct to update _config['url']
- $paginator = new PaginatorHelper($this->View);
- $paginator->options(['model' => 'Article']);
- $result = $paginator->generateUrl(['sort' => 'name']);
- $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name&article%5Bpuppy%5D=no';
- $this->assertEquals($expected, $result);
- $result = $paginator->generateUrl([]);
- $expected = '/posts/index?article%5Bpage%5D=3&article%5Bpuppy%5D=no';
- $this->assertEquals($expected, $result);
- }
- /**
- * testOptions method
- *
- * @return void
- */
- public function testOptions()
- {
- $this->Paginator->options = [];
- $this->Paginator->request->params = [];
- $options = ['paging' => ['Article' => [
- 'direction' => 'desc',
- 'sort' => 'title'
- ]]];
- $this->Paginator->options($options);
- $expected = ['Article' => [
- 'direction' => 'desc',
- 'sort' => 'title'
- ]];
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- $this->Paginator->options = [];
- $this->Paginator->request->params = [];
- $options = ['Article' => [
- 'direction' => 'desc',
- 'sort' => 'title'
- ]];
- $this->Paginator->options($options);
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- $options = ['paging' => ['Article' => [
- 'direction' => 'desc',
- 'sort' => 'Article.title'
- ]]];
- $this->Paginator->options($options);
- $expected = ['Article' => [
- 'direction' => 'desc',
- 'sort' => 'Article.title'
- ]];
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- }
- /**
- * testPassedArgsMergingWithUrlOptions method
- *
- * @return void
- */
- public function testPassedArgsMergingWithUrlOptions()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => ['2']],
- ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => 1, 'current' => 3, 'count' => 13,
- 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
- 'sort' => null, 'direction' => null,
- ]
- ];
- $this->Paginator->request->params['pass'] = [2];
- $this->Paginator->request->query = ['page' => 1, 'foo' => 'bar', 'x' => 'y', 'num' => 0];
- $this->View->request = $this->Paginator->request;
- $this->Paginator = new PaginatorHelper($this->View);
- $result = $this->Paginator->sort('title');
- $expected = [
- 'a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&sort=title&direction=asc'],
- 'Title',
- '/a'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers();
- $expected = [
- ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=7']], '7', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&page=2', 'rel' => 'next'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that generated URLs don't include sort and direction parameters
- *
- * @return void
- */
- public function testDefaultSortRemovedFromUrl()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
- ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => 1, 'current' => 3, 'count' => 13,
- 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
- 'sort' => 'Article.title', 'direction' => 'ASC',
- 'sortDefault' => 'Article.title', 'directionDefault' => 'ASC'
- ]
- ];
- $result = $this->Paginator->next('Next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['rel' => 'next', 'href' => '/articles/index?page=2'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test the prev() method.
- *
- * @return void
- */
- public function testPrev()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ]
- ];
- $result = $this->Paginator->prev('<< Previous');
- $expected = [
- 'li' => ['class' => 'prev disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- '<< Previous',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => 'Prev']);
- $expected = [
- 'li' => ['class' => 'prev disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- 'Prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => false]);
- $this->assertEquals('', $result, 'disabled + no text = no link');
- $this->Paginator->request->params['paging']['Client']['page'] = 2;
- $this->Paginator->request->params['paging']['Client']['prevPage'] = true;
- $result = $this->Paginator->prev('<< Previous');
- $expected = [
- 'li' => ['class' => 'prev'],
- 'a' => ['href' => '/index', 'rel' => 'prev'],
- '<< Previous',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('Prev', [
- 'templates' => [
- 'prevActive' => '<a rel="prev" href="{{url}}">{{text}}</a>'
- ]
- ]);
- $expected = [
- 'a' => ['href' => '/index', 'rel' => 'prev'],
- 'Prev',
- '/a',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that prev() and the shared implementation underneath picks up from options
- *
- * @return void
- */
- public function testPrevWithOptions()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
- 'nextPage' => false, 'pageCount' => 2,
- 'limit' => 10,
- ]
- ];
- $this->Paginator->options(['url' => [12, 'page' => 3]]);
- $result = $this->Paginator->prev('Prev', ['url' => ['foo' => 'bar']]);
- $expected = [
- 'li' => ['class' => 'prev'],
- 'a' => ['href' => '/index/12?limit=10&foo=bar', 'rel' => 'prev'],
- 'Prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test the next() method.
- *
- * @return void
- */
- public function testNext()
- {
- $result = $this->Paginator->next('Next >>');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
- 'Next >>',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next', [
- 'templates' => [
- 'nextActive' => '<a rel="next" href="{{url}}">{{text}}</a>'
- ]
- ]);
- $expected = [
- 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
- 'Next',
- '/a',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next >>', ['escape' => false]);
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
- 'preg:/Next >>/',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test next() with disabled links
- *
- * @return void
- */
- public function testNextDisabled()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 5,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 5,
- ]
- ];
- $result = $this->Paginator->next('Next >>');
- $expected = [
- 'li' => ['class' => 'next disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- 'Next >>',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next >>', ['disabledTitle' => 'Next']);
- $expected = [
- 'li' => ['class' => 'next disabled'],
- 'a' => ['href' => '', 'onclick' => 'return false;'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next >>', ['disabledTitle' => false]);
- $this->assertEquals('', $result, 'disabled + no text = no link');
- }
- /**
- * Test next() with a model argument.
- *
- * @return void
- */
- public function testNextAndPrevNonDefaultModel()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ],
- 'Server' => [
- 'page' => 5,
- 'current' => 1,
- 'count' => 5,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 5,
- ]
- ];
- $result = $this->Paginator->next('Next', [
- 'model' => 'Client'
- ]);
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
- 'Next',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('Prev', [
- 'model' => 'Client'
- ]);
- $expected = '<li class="prev disabled"><a href="" onclick="return false;">Prev</a></li>';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->next('Next', [
- 'model' => 'Server'
- ]);
- $expected = '<li class="next disabled"><a href="" onclick="return false;">Next</a></li>';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->prev('Prev', [
- 'model' => 'Server'
- ]);
- $expected = [
- 'li' => ['class' => 'prev'],
- 'a' => ['href' => '/index?page=4', 'rel' => 'prev'],
- 'Prev',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testNumbers method
- *
- * @return void
- */
- public function testNumbers()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 8,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers();
- $expected = [
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['first' => 'first', 'last' => 'last']);
- $expected = [
- ['li' => ['class' => 'first']], ['a' => ['href' => '/index']], 'first', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => ['class' => 'last']], ['a' => ['href' => '/index?page=15']], 'last', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['first' => '2', 'last' => '8']);
- $expected = [
- ['li' => ['class' => 'first']], ['a' => ['href' => '/index']], '2', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => ['class' => 'last']], ['a' => ['href' => '/index?page=15']], '8', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['first' => '8', 'last' => '8']);
- $expected = [
- ['li' => ['class' => 'first']], ['a' => ['href' => '/index']], '8', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => ['class' => 'last']], ['a' => ['href' => '/index?page=15']], '8', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers();
- $expected = [
- ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 14,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers();
- $expected = [
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '14', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=15']], '15', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 2,
- 'current' => 3,
- 'count' => 27,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 9,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['last' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 15,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=14']], '14', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '15', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 10,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=14']], '14', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=15']], '15', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 6,
- 'current' => 15,
- 'count' => 623,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 42,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=42']], '42', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 37,
- 'current' => 15,
- 'count' => 623,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 42,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=33']], '33', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=34']], '34', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=35']], '35', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=36']], '36', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '37', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=38']], '38', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=39']], '39', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=40']], '40', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=41']], '41', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=42']], '42', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testNumbersPages method
- *
- * @return void
- */
- public function testNumbersMulti()
- {
- $expected = [
- 1 => '*1 2 3 4 5 6 7 ',
- 2 => '1 *2 3 4 5 6 7 ',
- 3 => '1 2 *3 4 5 6 7 ',
- 4 => '1 2 3 *4 5 6 7 ',
- 5 => '1 2 3 4 *5 6 7 ',
- 6 => '1 2 3 4 5 *6 7 ',
- 7 => '1 2 3 4 5 6 *7 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 7);
- $this->assertEquals($expected, $result);
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 7, ['first' => 'F', 'last' => 'L']);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ',
- 2 => '1 *2 3 4 5 6 7 8 9 ',
- 3 => '1 2 *3 4 5 6 7 8 9 ',
- 4 => '1 2 3 *4 5 6 7 8 9 ',
- 5 => '1 2 3 4 *5 6 7 8 9 ',
- 6 => '2 3 4 5 *6 7 8 9 10 ',
- 7 => '3 4 5 6 *7 8 9 10 11 ',
- 10 => '6 7 8 9 *10 11 12 13 14 ',
- 15 => '11 12 13 14 *15 16 17 18 19 ',
- 16 => '12 13 14 15 *16 17 18 19 20 ',
- 17 => '12 13 14 15 16 *17 18 19 20 ',
- 18 => '12 13 14 15 16 17 *18 19 20 ',
- 19 => '12 13 14 15 16 17 18 *19 20 ',
- 20 => '12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ',
- 2 => '1 *2 3 4 5 6 7 8 9 ',
- 3 => '1 2 *3 4 5 6 7 8 9 ',
- 4 => '1 2 3 *4 5 6 7 8 9 ',
- 5 => '1 2 3 4 *5 6 7 8 9 ',
- 6 => '1 2 3 4 5 *6 7 8 9 10 ',
- 7 => '1 2 3 4 5 6 *7 8 9 10 11 ',
- 8 => '<F ... 4 5 6 7 *8 9 10 11 12 ',
- 9 => '<F ... 5 6 7 8 *9 10 11 12 13 ',
- 10 => '<F ... 6 7 8 9 *10 11 12 13 14 ',
- 15 => '<F ... 11 12 13 14 *15 16 17 18 19 ',
- 16 => '<F ... 12 13 14 15 *16 17 18 19 20 ',
- 17 => '<F ... 12 13 14 15 16 *17 18 19 20 ',
- 18 => '<F ... 12 13 14 15 16 17 *18 19 20 ',
- 19 => '<F ... 12 13 14 15 16 17 18 *19 20 ',
- 20 => '<F ... 12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 'F']);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ',
- 2 => '1 *2 3 4 5 6 7 8 9 ',
- 3 => '1 2 *3 4 5 6 7 8 9 ',
- 4 => '1 2 3 *4 5 6 7 8 9 ',
- 5 => '1 2 3 4 *5 6 7 8 9 ',
- 6 => '1 2 3 4 5 *6 7 8 9 10 ',
- 7 => '1 2 3 4 5 6 *7 8 9 10 11 ',
- 8 => '1 2 3 4 5 6 7 *8 9 10 11 12 ',
- 9 => '1 2 ... 5 6 7 8 *9 10 11 12 13 ',
- 10 => '1 2 ... 6 7 8 9 *10 11 12 13 14 ',
- 15 => '1 2 ... 11 12 13 14 *15 16 17 18 19 ',
- 16 => '1 2 ... 12 13 14 15 *16 17 18 19 20 ',
- 17 => '1 2 ... 12 13 14 15 16 *17 18 19 20 ',
- 18 => '1 2 ... 12 13 14 15 16 17 *18 19 20 ',
- 19 => '1 2 ... 12 13 14 15 16 17 18 *19 20 ',
- 20 => '1 2 ... 12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 2]);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ... L> ',
- 2 => '1 *2 3 4 5 6 7 8 9 ... L> ',
- 3 => '1 2 *3 4 5 6 7 8 9 ... L> ',
- 4 => '1 2 3 *4 5 6 7 8 9 ... L> ',
- 5 => '1 2 3 4 *5 6 7 8 9 ... L> ',
- 6 => '2 3 4 5 *6 7 8 9 10 ... L> ',
- 7 => '3 4 5 6 *7 8 9 10 11 ... L> ',
- 8 => '4 5 6 7 *8 9 10 11 12 ... L> ',
- 9 => '5 6 7 8 *9 10 11 12 13 ... L> ',
- 10 => '6 7 8 9 *10 11 12 13 14 ... L> ',
- 11 => '7 8 9 10 *11 12 13 14 15 ... L> ',
- 12 => '8 9 10 11 *12 13 14 15 16 ... L> ',
- 13 => '9 10 11 12 *13 14 15 16 17 ... L> ',
- 14 => '10 11 12 13 *14 15 16 17 18 19 20 ',
- 15 => '11 12 13 14 *15 16 17 18 19 20 ',
- 16 => '12 13 14 15 *16 17 18 19 20 ',
- 17 => '12 13 14 15 16 *17 18 19 20 ',
- 18 => '12 13 14 15 16 17 *18 19 20 ',
- 19 => '12 13 14 15 16 17 18 *19 20 ',
- 20 => '12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['last' => 'L']);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ... L> ',
- 2 => '1 *2 3 4 5 6 7 8 9 ... L> ',
- 3 => '1 2 *3 4 5 6 7 8 9 ... L> ',
- 4 => '1 2 3 *4 5 6 7 8 9 ... L> ',
- 5 => '1 2 3 4 *5 6 7 8 9 ... L> ',
- 6 => '1 2 3 4 5 *6 7 8 9 10 ... L> ',
- 7 => '1 2 3 4 5 6 *7 8 9 10 11 ... L> ',
- 8 => '<F ... 4 5 6 7 *8 9 10 11 12 ... L> ',
- 9 => '<F ... 5 6 7 8 *9 10 11 12 13 ... L> ',
- 10 => '<F ... 6 7 8 9 *10 11 12 13 14 ... L> ',
- 11 => '<F ... 7 8 9 10 *11 12 13 14 15 ... L> ',
- 12 => '<F ... 8 9 10 11 *12 13 14 15 16 ... L> ',
- 13 => '<F ... 9 10 11 12 *13 14 15 16 17 ... L> ',
- 14 => '<F ... 10 11 12 13 *14 15 16 17 18 19 20 ',
- 15 => '<F ... 11 12 13 14 *15 16 17 18 19 20 ',
- 16 => '<F ... 12 13 14 15 *16 17 18 19 20 ',
- 17 => '<F ... 12 13 14 15 16 *17 18 19 20 ',
- 18 => '<F ... 12 13 14 15 16 17 *18 19 20 ',
- 19 => '<F ... 12 13 14 15 16 17 18 *19 20 ',
- 20 => '<F ... 12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 'F', 'last' => 'L']);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ... 19 20 ',
- 2 => '1 *2 3 4 5 6 7 8 9 ... 19 20 ',
- 3 => '1 2 *3 4 5 6 7 8 9 ... 19 20 ',
- 4 => '1 2 3 *4 5 6 7 8 9 ... 19 20 ',
- 5 => '1 2 3 4 *5 6 7 8 9 ... 19 20 ',
- 6 => '1 2 3 4 5 *6 7 8 9 10 ... 19 20 ',
- 7 => '1 2 3 4 5 6 *7 8 9 10 11 ... 19 20 ',
- 8 => '1 2 3 4 5 6 7 *8 9 10 11 12 ... 19 20 ',
- 9 => '1 2 ... 5 6 7 8 *9 10 11 12 13 ... 19 20 ',
- 10 => '1 2 ... 6 7 8 9 *10 11 12 13 14 ... 19 20 ',
- 11 => '1 2 ... 7 8 9 10 *11 12 13 14 15 ... 19 20 ',
- 12 => '1 2 ... 8 9 10 11 *12 13 14 15 16 ... 19 20 ',
- 13 => '1 2 ... 9 10 11 12 *13 14 15 16 17 18 19 20 ',
- 14 => '1 2 ... 10 11 12 13 *14 15 16 17 18 19 20 ',
- 15 => '1 2 ... 11 12 13 14 *15 16 17 18 19 20 ',
- 16 => '1 2 ... 12 13 14 15 *16 17 18 19 20 ',
- 17 => '1 2 ... 12 13 14 15 16 *17 18 19 20 ',
- 18 => '1 2 ... 12 13 14 15 16 17 *18 19 20 ',
- 19 => '1 2 ... 12 13 14 15 16 17 18 *19 20 ',
- 20 => '1 2 ... 12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 2, 'last' => 2]);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 6 7 8 9 ... 19 20 ',
- 2 => '1 *2 3 4 5 6 7 8 9 ... 19 20 ',
- 3 => '1 2 *3 4 5 6 7 8 9 ... 19 20 ',
- 4 => '1 2 3 *4 5 6 7 8 9 ... 19 20 ',
- 5 => '1 2 3 4 *5 6 7 8 9 ... 19 20 ',
- 6 => '2 3 4 5 *6 7 8 9 10 ... 19 20 ',
- 7 => '3 4 5 6 *7 8 9 10 11 ... 19 20 ',
- 8 => '4 5 6 7 *8 9 10 11 12 ... 19 20 ',
- 9 => '5 6 7 8 *9 10 11 12 13 ... 19 20 ',
- 10 => '6 7 8 9 *10 11 12 13 14 ... 19 20 ',
- 11 => '7 8 9 10 *11 12 13 14 15 ... 19 20 ',
- 12 => '8 9 10 11 *12 13 14 15 16 ... 19 20 ',
- 13 => '9 10 11 12 *13 14 15 16 17 18 19 20 ',
- 14 => '10 11 12 13 *14 15 16 17 18 19 20 ',
- 15 => '11 12 13 14 *15 16 17 18 19 20 ',
- 16 => '12 13 14 15 *16 17 18 19 20 ',
- 17 => '12 13 14 15 16 *17 18 19 20 ',
- 18 => '12 13 14 15 16 17 *18 19 20 ',
- 19 => '12 13 14 15 16 17 18 *19 20 ',
- 20 => '12 13 14 15 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['last' => 2]);
- $this->assertEquals($expected, $result);
- }
- /**
- * Retrieves result of PaginatorHelper::numbers for multiple pages
- *
- * @param int[] $pagesToCheck Pages to get result for
- * @param int $pageCount Number of total pages
- * @param array $options Options for PaginatorHelper::numbers
- * @return string[]
- */
- protected function getNumbersForMultiplePages($pagesToCheck, $pageCount, $options = [])
- {
- $options['templates'] = [
- 'first' => '<{{text}} ',
- 'last' => '{{text}}> ',
- 'number' => '{{text}} ',
- 'current' => '*{{text}} ',
- 'ellipsis' => '... ',
- ];
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'pageCount' => $pageCount,
- ]
- ];
- $result = [];
- foreach ($pagesToCheck as $page) {
- $this->Paginator->request->params['paging']['Client']['page'] = $page;
- $result[$page] = $this->Paginator->numbers($options);
- }
- return $result;
- }
- /**
- * Test that numbers() lets you overwrite templates.
- *
- * The templates file has no li elements.
- *
- * @return void
- */
- public function testNumbersTemplates()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 8,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers(['templates' => 'htmlhelper_tags']);
- $expected = [
- ['a' => ['href' => '/index?page=4']], '4', '/a',
- ['a' => ['href' => '/index?page=5']], '5', '/a',
- ['a' => ['href' => '/index?page=6']], '6', '/a',
- ['a' => ['href' => '/index?page=7']], '7', '/a',
- 'span' => ['class' => 'active'], '8', '/span',
- ['a' => ['href' => '/index?page=9']], '9', '/a',
- ['a' => ['href' => '/index?page=10']], '10', '/a',
- ['a' => ['href' => '/index?page=11']], '11', '/a',
- ['a' => ['href' => '/index?page=12']], '12', '/a',
- ];
- $this->assertHtml($expected, $result);
- $this->assertContains(
- '<li',
- $this->Paginator->templater()->get('current'),
- 'Templates were not restored.'
- );
- }
- /**
- * Test modulus option for numbers()
- *
- * @return void
- */
- public function testNumbersModulus()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 10,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 3,
- ]
- ];
- $result = $this->Paginator->numbers(['modulus' => 10]);
- $expected = [
- ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['modulus' => 3]);
- $expected = [
- ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 4895,
- 'current' => 10,
- 'count' => 48962,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 4897,
- ]
- ];
- $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4894']], '4,894', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '4,895', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 3;
- $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 5, 'last' => 5]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4893']], '4,893', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4894']], '4,894', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4895']], '4,895', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 4893;
- $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4891']], '4,891', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4892']], '4,892', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '4,893', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4894']], '4,894', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4895']], '4,895', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 58;
- $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=56']], '56', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=57']], '57', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '58', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=59']], '59', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=60']], '60', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4893']], '4,893', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4894']], '4,894', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4895']], '4,895', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 5;
- $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4893']], '4,893', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4894']], '4,894', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4895']], '4,895', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 3;
- $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 3;
- $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 0, 'last' => 2]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test modulus option for numbers()
- *
- * @return void
- */
- public function testNumbersModulusMulti()
- {
- $expected = [
- 1 => '*1 2 3 4 ',
- 2 => '1 *2 3 4 ',
- 3 => '1 2 *3 4 ',
- 4 => '2 3 *4 5 ',
- 5 => '3 4 *5 6 ',
- 6 => '4 5 *6 7 ',
- 7 => '4 5 6 *7 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 7, ['modulus' => 3]);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 ... L> ',
- 2 => '1 *2 3 4 ... L> ',
- 3 => '1 2 *3 4 ... L> ',
- 4 => '1 2 3 *4 5 6 7 ',
- 5 => '1 2 3 4 *5 6 7 ',
- 6 => '<F ... 4 5 *6 7 ',
- 7 => '<F ... 4 5 6 *7 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 7, ['modulus' => 3, 'first' => 'F', 'last' => 'L']);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 ... 19 20 ',
- 2 => '1 *2 3 ... 19 20 ',
- 3 => '1 2 *3 4 ... 19 20 ',
- 4 => '1 2 3 *4 5 ... 19 20 ',
- 5 => '1 2 3 4 *5 6 ... 19 20 ',
- 6 => '1 2 ... 5 *6 7 ... 19 20 ',
- 15 => '1 2 ... 14 *15 16 ... 19 20 ',
- 16 => '1 2 ... 15 *16 17 18 19 20 ',
- 17 => '1 2 ... 16 *17 18 19 20 ',
- 18 => '1 2 ... 17 *18 19 20 ',
- 19 => '1 2 ... 18 *19 20 ',
- 20 => '1 2 ... 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 2, 'modulus' => 2, 'last' => 2]);
- $this->assertEquals($expected, $result);
- $expected = [
- 1 => '*1 2 3 4 5 ... 16 17 18 19 20 ',
- 2 => '1 *2 3 4 5 ... 16 17 18 19 20 ',
- 3 => '1 2 *3 4 5 ... 16 17 18 19 20 ',
- 4 => '1 2 3 *4 5 6 ... 16 17 18 19 20 ',
- 5 => '1 2 3 4 *5 6 7 ... 16 17 18 19 20 ',
- 6 => '1 2 3 4 5 *6 7 8 ... 16 17 18 19 20 ',
- 7 => '1 2 3 4 5 6 *7 8 9 ... 16 17 18 19 20 ',
- 8 => '1 2 3 4 5 6 7 *8 9 10 ... 16 17 18 19 20 ',
- 9 => '1 2 3 4 5 6 7 8 *9 10 11 ... 16 17 18 19 20 ',
- 10 => '1 2 3 4 5 ... 8 9 *10 11 12 ... 16 17 18 19 20 ',
- 11 => '1 2 3 4 5 ... 9 10 *11 12 13 ... 16 17 18 19 20 ',
- 12 => '1 2 3 4 5 ... 10 11 *12 13 14 15 16 17 18 19 20 ',
- 13 => '1 2 3 4 5 ... 11 12 *13 14 15 16 17 18 19 20 ',
- 14 => '1 2 3 4 5 ... 12 13 *14 15 16 17 18 19 20 ',
- 15 => '1 2 3 4 5 ... 13 14 *15 16 17 18 19 20 ',
- 16 => '1 2 3 4 5 ... 14 15 *16 17 18 19 20 ',
- 17 => '1 2 3 4 5 ... 15 16 *17 18 19 20 ',
- 18 => '1 2 3 4 5 ... 16 17 *18 19 20 ',
- 19 => '1 2 3 4 5 ... 16 17 18 *19 20 ',
- 20 => '1 2 3 4 5 ... 16 17 18 19 *20 ',
- ];
- $result = $this->getNumbersForMultiplePages(array_keys($expected), 20, ['first' => 5, 'modulus' => 4, 'last' => 5]);
- $this->assertEquals($expected, $result);
- }
- /**
- * Tests that disabling modulus displays all page links.
- *
- * @return void
- */
- public function testModulusDisabled()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 4,
- 'current' => 2,
- 'count' => 30,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 6,
- ]
- ];
- $result = $this->Paginator->numbers(['modulus' => false]);
- $expected = [
- ['li' => []], '<a href="/index"', '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
- ['li' => ['class' => 'active']], ['a' => ['href' => '']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that numbers() with url options.
- *
- * @return void
- */
- public function testNumbersWithUrlOptions()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 8,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- ]
- ];
- $result = $this->Paginator->numbers(['url' => ['#' => 'foo']]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index?page=4#foo']], '4', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=5#foo']], '5', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=6#foo']], '6', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=7#foo']], '7', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=9#foo']], '9', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=10#foo']], '10', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=11#foo']], '11', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=12#foo']], '12', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 3,
- 'current' => 10,
- 'count' => 48962,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 4897,
- ]
- ];
- $result = $this->Paginator->numbers([
- 'first' => 2,
- 'modulus' => 2,
- 'last' => 2,
- 'url' => ['foo' => 'bar']]);
- $expected = [
- ['li' => []], ['a' => ['href' => '/index?foo=bar']], '1', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=2&foo=bar']], '2', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4&foo=bar']], '4', '/a', '/li',
- ['li' => ['class' => 'ellipsis']], '…', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4896&foo=bar']], '4,896', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/index?page=4897&foo=bar']], '4,897', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test numbers() with routing parameters.
- *
- * @return void
- */
- public function testNumbersRouting()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 2,
- 'current' => 2,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 3,
- 'pageCount' => 3,
- ]
- ];
- $request = new ServerRequest();
- $request->addParams([
- 'controller' => 'clients', 'action' => 'index', 'plugin' => null
- ]);
- $request->base = '';
- $request->here = '/clients/index?page=2';
- $request->webroot = '/';
- Router::setRequestInfo($request);
- $result = $this->Paginator->numbers();
- $expected = [
- ['li' => []], ['a' => ['href' => '/clients/index']], '1', '/a', '/li',
- ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
- ['li' => []], ['a' => ['href' => '/clients/index?page=3']], '3', '/a', '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that numbers() works with the non default model.
- *
- * @return void
- */
- public function testNumbersNonDefaultModel()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ],
- 'Server' => [
- 'page' => 5,
- 'current' => 1,
- 'count' => 5,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 5,
- ]
- ];
- $result = $this->Paginator->numbers(['model' => 'Server']);
- $this->assertContains('<li class="active"><a href="">5</a></li>', $result);
- $this->assertNotContains('<li class="active"><a href="">1</a></li>', $result);
- $result = $this->Paginator->numbers(['model' => 'Client']);
- $this->assertContains('<li class="active"><a href="">1</a></li>', $result);
- $this->assertNotContains('<li class="active"><a href="">5</a></li>', $result);
- }
- /**
- * test first() and last() with tag options
- *
- * @return void
- */
- public function testFirstAndLastTag()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 2;
- $result = $this->Paginator->first('<<');
- $expected = [
- 'li' => ['class' => 'first'],
- 'a' => ['href' => '/index'],
- '<<',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->first('5');
- $expected = [
- 'li' => ['class' => 'first'],
- 'a' => ['href' => '/index'],
- '5',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(2);
- $expected = [
- '<li',
- ['a' => ['href' => '/index?page=6']], '6', '/a',
- '/li',
- '<li',
- ['a' => ['href' => '/index?page=7']], '7', '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last('9');
- $expected = [
- 'li' => ['class' => 'last'],
- 'a' => ['href' => '/index?page=7'],
- '9',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test that on the last page you don't get a link ot the last page.
- *
- * @return void
- */
- public function testLastNoOutput()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 15;
- $this->Paginator->request->params['paging']['Article']['pageCount'] = 15;
- $result = $this->Paginator->last();
- $expected = '';
- $this->assertEquals($expected, $result);
- }
- /**
- * test first() with a the model parameter.
- *
- * @return void
- */
- public function testFirstNonDefaultModel()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 1;
- $this->Paginator->request->params['paging']['Client'] = [
- 'page' => 3,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ];
- $result = $this->Paginator->first('first', ['model' => 'Article']);
- $this->assertEquals('', $result);
- $result = $this->Paginator->first('first', ['model' => 'Client']);
- $expected = [
- 'li' => ['class' => 'first'],
- 'a' => ['href' => '/index'],
- 'first',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test first() on the first page.
- *
- * @return void
- */
- public function testFirstEmpty()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 1;
- $result = $this->Paginator->first();
- $expected = '';
- $this->assertEquals($expected, $result);
- }
- /**
- * test first() and options()
- *
- * @return void
- */
- public function testFirstFullBaseUrl()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $this->Paginator->request->params['paging']['Article']['direction'] = 'DESC';
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->options(['url' => ['_full' => true]]);
- $result = $this->Paginator->first();
- $expected = [
- 'li' => ['class' => 'first'],
- ['a' => [
- 'href' => Configure::read('App.fullBaseUrl') . '/index?sort=Article.title&direction=DESC'
- ]],
- '<< first',
- '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test first() on the fence-post
- *
- * @return void
- */
- public function testFirstBoundaries()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 3;
- $result = $this->Paginator->first();
- $expected = [
- 'li' => ['class' => 'first'],
- 'a' => ['href' => '/index'],
- '<< first',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->first(2);
- $expected = [
- '<li',
- ['a' => ['href' => '/index']], '1', '/a',
- '/li',
- '<li',
- ['a' => ['href' => '/index?page=2']], '2', '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 2;
- $result = $this->Paginator->first(3);
- $this->assertEquals('', $result, 'When inside the first links range, no links should be made');
- }
- /**
- * test params() method
- *
- * @return void
- */
- public function testParams()
- {
- $result = $this->Paginator->params();
- $this->assertArrayHasKey('page', $result);
- $this->assertArrayHasKey('pageCount', $result);
- $result = $this->Paginator->params('Nope');
- $this->assertEquals([], $result);
- }
- /**
- * test param() method
- *
- * @return void
- */
- public function testParam()
- {
- $result = $this->Paginator->param('count');
- $this->assertSame(62, $result);
- $result = $this->Paginator->param('imaginary');
- $this->assertNull($result);
- }
- /**
- * test last() method
- *
- * @return void
- */
- public function testLast()
- {
- $result = $this->Paginator->last();
- $expected = [
- 'li' => ['class' => 'last'],
- 'a' => ['href' => '/index?page=7'],
- 'last >>',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(1);
- $expected = [
- '<li',
- 'a' => ['href' => '/index?page=7'],
- '7',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Article']['page'] = 6;
- $result = $this->Paginator->last(2);
- $expected = [
- '<li',
- ['a' => ['href' => '/index?page=6']], '6', '/a',
- '/li',
- '<li',
- ['a' => ['href' => '/index?page=7']], '7', '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(3);
- $this->assertEquals('', $result, 'When inside the last links range, no links should be made');
- }
- /**
- * test the options for last()
- *
- * @return void
- */
- public function testLastOptions()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 4,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- 'sort' => 'Client.name',
- 'direction' => 'DESC',
- ]
- ];
- $result = $this->Paginator->last();
- $expected = [
- 'li' => ['class' => 'last'],
- 'a' => [
- 'href' => '/index?page=15&sort=Client.name&direction=DESC',
- ],
- 'last >>', '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(1);
- $expected = [
- '<li',
- ['a' => ['href' => '/index?page=15&sort=Client.name&direction=DESC']], '15', '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(2);
- $expected = [
- '<li',
- ['a' => ['href' => '/index?page=14&sort=Client.name&direction=DESC']], '14', '/a',
- '/li',
- '<li',
- ['a' => ['href' => '/index?page=15&sort=Client.name&direction=DESC']], '15', '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test last() with a the model parameter.
- *
- * @return void
- */
- public function testLastNonDefaultModel()
- {
- $this->Paginator->request->params['paging']['Article']['page'] = 7;
- $this->Paginator->request->params['paging']['Client'] = [
- 'page' => 3,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ];
- $result = $this->Paginator->last('last', ['model' => 'Article']);
- $this->assertEquals('', $result);
- $result = $this->Paginator->last('last', ['model' => 'Client']);
- $expected = [
- 'li' => ['class' => 'last'],
- 'a' => ['href' => '/index?page=5'],
- 'last',
- '/a',
- '/li'
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * testCounter method
- *
- * @return void
- */
- public function testCounter()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'perPage' => 3,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- 'limit' => 3,
- 'sort' => 'Client.name',
- 'order' => 'DESC',
- ]
- ];
- $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, ';
- $input .= 'starting on record {{start}}, ending on {{end}}';
- $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
- $expected .= 'ending on 3';
- $result = $this->Paginator->counter($input);
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->counter(['format' => 'pages']);
- $expected = '1 of 5';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->counter(['format' => 'range']);
- $expected = '1 - 3 of 13';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->counter('Showing {{page}} of {{pages}} {{model}}');
- $this->assertEquals('Showing 1 of 5 clients', $result);
- }
- /**
- * Tests that numbers are formatted according to the locale when using counter()
- *
- * @return void
- */
- public function testCounterBigNumbers()
- {
- $this->Paginator->request->params['paging'] = [
- 'Client' => [
- 'page' => 1523,
- 'current' => 1230,
- 'count' => 234567,
- 'perPage' => 3000,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 1000,
- 'limit' => 5000,
- 'sort' => 'Client.name',
- 'order' => 'DESC',
- ]
- ];
- $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, ';
- $input .= 'starting on record {{start}}, ending on {{end}}';
- $expected = 'Page 1,523 of 1,000, showing 1,230 records out of 234,567 total, ';
- $expected .= 'starting on record 4,566,001, ending on 234,567';
- $result = $this->Paginator->counter($input);
- $this->assertEquals($expected, $result);
- I18n::locale('de-DE');
- $expected = 'Page 1.523 of 1.000, showing 1.230 records out of 234.567 total, ';
- $expected .= 'starting on record 4.566.001, ending on 234.567';
- $result = $this->Paginator->counter($input);
- $this->assertEquals($expected, $result);
- }
- /**
- * testHasPage method
- *
- * @return void
- */
- public function testHasPage()
- {
- $result = $this->Paginator->hasPage('Article', 15);
- $this->assertFalse($result);
- $result = $this->Paginator->hasPage('UndefinedModel', 2);
- $this->assertFalse($result);
- $result = $this->Paginator->hasPage('Article', 2);
- $this->assertTrue($result);
- $result = $this->Paginator->hasPage(2);
- $this->assertTrue($result);
- }
- /**
- * testNextLinkUsingDotNotation method
- *
- * @return void
- */
- public function testNextLinkUsingDotNotation()
- {
- Router::setRequestInfo([
- ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
- ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
- ]);
- $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
- $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
- $this->Paginator->request->params['paging']['Article']['page'] = 1;
- $test = ['url' => [
- 'page' => '1',
- 'sort' => 'Article.title',
- 'direction' => 'asc',
- ]];
- $this->Paginator->options($test);
- $result = $this->Paginator->next('Next');
- $expected = [
- 'li' => ['class' => 'next'],
- 'a' => [
- 'href' => '/accounts/index?page=2&sort=Article.title&direction=asc',
- 'rel' => 'next'
- ],
- 'Next',
- '/a',
- '/li',
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * test the current() method
- *
- * @return void
- */
- public function testCurrent()
- {
- $result = $this->Paginator->current();
- $this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result);
- $result = $this->Paginator->current('Incorrect');
- $this->assertEquals(1, $result);
- }
- /**
- * test the total() method
- *
- * @return void
- */
- public function testTotal()
- {
- $result = $this->Paginator->total();
- $this->assertSame($this->Paginator->request->params['paging']['Article']['pageCount'], $result);
- $result = $this->Paginator->total('Incorrect');
- $this->assertSame(0, $result);
- }
- /**
- * test the defaultModel() method
- *
- * @return void
- */
- public function testNoDefaultModel()
- {
- $this->Paginator->request = new ServerRequest();
- $this->assertNull($this->Paginator->defaultModel());
- $this->Paginator->defaultModel('Article');
- $this->assertEquals('Article', $this->Paginator->defaultModel());
- $this->Paginator->options(['model' => 'Client']);
- $this->assertEquals('Client', $this->Paginator->defaultModel());
- }
- /**
- * test the numbers() method when there is only one page
- *
- * @return void
- */
- public function testWithOnePage()
- {
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => 1,
- 'current' => 2,
- 'count' => 2,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 1,
- ]
- ];
- $this->assertFalse($this->Paginator->numbers());
- $this->assertFalse($this->Paginator->first());
- $this->assertFalse($this->Paginator->last());
- }
- /**
- * test the numbers() method when there is only one page
- *
- * @return void
- */
- public function testWithZeroPages()
- {
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => 0,
- 'current' => 0,
- 'count' => 0,
- 'perPage' => 10,
- 'prevPage' => false,
- 'nextPage' => false,
- 'pageCount' => 0,
- 'limit' => 10,
- ]
- ];
- $result = $this->Paginator->counter(['format' => 'pages']);
- $expected = '0 of 1';
- $this->assertEquals($expected, $result);
- }
- /**
- * Test data for meta()
- *
- * @return array
- */
- public function dataMetaProvider()
- {
- return [
- // Verifies that no next and prev links are created for single page results.
- [1, false, false, 1, [], ''],
- // Verifies that first and last pages are created for single page results.
- [1, false, false, 1, ['first' => true, 'last' => true], '<link href="http://localhost/index" rel="first"/>' .
- '<link href="http://localhost/index" rel="last"/>'],
- // Verifies that first page is created for single page results.
- [1, false, false, 1, ['first' => true], '<link href="http://localhost/index" rel="first"/>'],
- // Verifies that last page is created for single page results.
- [1, false, false, 1, ['last' => true], '<link href="http://localhost/index" rel="last"/>'],
- // Verifies that page 1 only has a next link.
- [1, false, true, 2, [], '<link href="http://localhost/index?page=2" rel="next"/>'],
- // Verifies that page 1 only has next, first and last link.
- [1, false, true, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
- '<link href="http://localhost/index" rel="first"/>' .
- '<link href="http://localhost/index?page=2" rel="last"/>'],
- // Verifies that page 1 only has next and first link.
- [1, false, true, 2, ['first' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
- '<link href="http://localhost/index" rel="first"/>'],
- // Verifies that page 1 only has next and last link.
- [1, false, true, 2, ['last' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
- '<link href="http://localhost/index?page=2" rel="last"/>'],
- // Verifies that the last page only has a prev link.
- [2, true, false, 2, [], '<link href="http://localhost/index" rel="prev"/>'],
- // Verifies that the last page only has a prev, first and last link.
- [2, true, false, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index" rel="prev"/>' .
- '<link href="http://localhost/index" rel="first"/>' .
- '<link href="http://localhost/index?page=2" rel="last"/>'],
- // Verifies that a page in the middle has both links.
- [5, true, true, 10, [], '<link href="http://localhost/index?page=4" rel="prev"/>' .
- '<link href="http://localhost/index?page=6" rel="next"/>'],
- // Verifies that a page in the middle has both links.
- [5, true, true, 10, ['first' => true, 'last' => true], '<link href="http://localhost/index?page=4" rel="prev"/>' .
- '<link href="http://localhost/index?page=6" rel="next"/>' .
- '<link href="http://localhost/index" rel="first"/>' .
- '<link href="http://localhost/index?page=10" rel="last"/>']
- ];
- }
- /**
- * @param int $page
- * @param int $prevPage
- * @param int $nextPage
- * @param int $pageCount
- * @param array $options
- * @param string $expected
- * @dataProvider dataMetaProvider
- */
- public function testMeta($page, $prevPage, $nextPage, $pageCount, $options, $expected)
- {
- $this->Paginator->request->params['paging'] = [
- 'Article' => [
- 'page' => $page,
- 'prevPage' => $prevPage,
- 'nextPage' => $nextPage,
- 'pageCount' => $pageCount,
- ]
- ];
- $result = $this->Paginator->meta($options);
- $this->assertSame($expected, $result);
- $this->assertEquals('', $this->View->fetch('meta'));
- $result = $this->Paginator->meta($options + ['block' => true]);
- $this->assertNull($result);
- $this->assertSame($expected, $this->View->fetch('meta'));
- }
- }
|