| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127 |
- <?php
- /**
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * 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://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @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\Network\Request;
- use Cake\Routing\Router;
- use Cake\TestSuite\TestCase;
- use Cake\View\Helper\PaginatorHelper;
- use Cake\View\View;
- /**
- * PaginatorHelperTest class
- *
- */
- class PaginatorHelperTest extends TestCase {
- /**
- * 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->Js = $this->getMock('Cake\View\Helper\PaginatorHelper', array(), array($this->View));
- $this->Paginator->request = new Request();
- $this->Paginator->request->addParams(array(
- 'paging' => array(
- 'Article' => array(
- 'page' => 1,
- 'current' => 9,
- 'count' => 62,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 7,
- 'sort' => null,
- 'direction' => null,
- 'limit' => null,
- )
- )
- ));
- Configure::write('Routing.prefixes', array());
- Router::reload();
- Router::connect('/:controller/:action/*');
- Router::connect('/:plugin/:controller/:action/*');
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->View, $this->Paginator);
- }
- /**
- * 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(array(
- array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
- array('base' => '', 'here' => '/accounts/', 'webroot' => '/')
- ));
- $this->Paginator->options(array('url' => array('param')));
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'current' => 9,
- 'count' => 62,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 7,
- 'sort' => 'date',
- 'direction' => 'asc',
- 'page' => 1,
- )
- );
- $result = $this->Paginator->sort('title');
- $expected = array(
- 'a' => array('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 = array(
- 'a' => array('href' => '/accounts/index/param?sort=date&direction=desc', 'class' => 'asc'),
- 'Date',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', 'TestTitle');
- $expected = array(
- 'a' => array('href' => '/accounts/index/param?sort=title&direction=asc'),
- 'TestTitle',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
- $expected = array(
- 'a' => array('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', array('asc' => 'ascending', 'desc' => 'descending'));
- $expected = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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', array('direction' => 'desc'));
- $expected = array(
- 'a' => array('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', array('direction' => 'asc'));
- $expected = array(
- 'a' => array('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', array('direction' => 'asc'));
- $expected = array(
- 'a' => array('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', array('direction' => 'desc'));
- $expected = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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(array(
- array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
- array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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(array(
- array('plugin' => null, 'controller' => 'accounts', 'action' => 'index',
- 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true')),
- array('base' => '/', 'here' => '/accounts/', 'webroot' => '/')
- ));
- $this->Paginator->options(array('url' => array('param')));
- $result = $this->Paginator->sort('title', 'TestTitle', array('direction' => 'desc'));
- $expected = array(
- 'a' => array('href' => '/accounts/index/param?sort=title&direction=desc'),
- 'TestTitle',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'), array('direction' => 'desc'));
- $expected = array(
- 'a' => array('href' => '/accounts/index/param?sort=title&direction=desc'),
- 'descending',
- '/a'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testSortLinksUsingDotNotation method
- *
- * @return void
- */
- public function testSortLinksUsingDotNotation() {
- Router::setRequestInfo(array(
- array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array()),
- array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('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 = array(
- 'a' => array('href' => '/accounts/index?sort=title&direction=asc'),
- 'Title',
- '/a'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testSortKey method
- *
- * @return void
- */
- public function testSortKey() {
- $result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
- $this->assertEquals('Article.title', $result);
- $result = $this->Paginator->sortKey('Article', array('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', array('direction' => 'asc'));
- $this->assertEquals('asc', $result);
- $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
- $this->assertEquals('desc', $result);
- $result = $this->Paginator->sortDir('Article', array('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', array('admin'));
- Router::reload();
- Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin'));
- Router::setRequestInfo(array(
- array('controller' => 'users', 'plugin' => null, 'action' => 'index', 'prefix' => 'admin'),
- array('base' => '', 'here' => '/admin/users', 'webroot' => '/')
- ));
- $this->Paginator->request->params['paging']['Article']['page'] = 1;
- $result = $this->Paginator->next('Next');
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array('href' => '/admin/users/index?page=2', 'rel' => 'next'),
- 'Next',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->options(array('url' => array('param')));
- $result = $this->Paginator->sort('title');
- $expected = array(
- 'a' => array('href' => '/admin/users/index/param?sort=title&direction=asc'),
- 'Title',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->options(array('url' => array('param')));
- $result = $this->Paginator->sort('Article.title', 'Title');
- $expected = array(
- 'a' => array('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(array(
- array('plugin' => null, 'controller' => 'articles', 'action' => 'index'),
- array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
- ));
- $this->Paginator->request->params['paging'] = array(
- 'Article' => array(
- '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 = array(
- 'li' => array('class' => 'next'),
- 'a' => array('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 = array(
- 'a' => array('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 = array('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 = array('sort' => 'Article.name', 'direction' => 'desc');
- $result = $this->Paginator->generateUrl($options);
- $this->assertEquals('/index?page=3&sort=Article.name&direction=desc', $result);
- }
- /**
- * test URL generation with prefix routes
- *
- * @return void
- */
- public function testUrlGenerationWithPrefixes() {
- Configure::write('Routing.prefixes', array('members'));
- Router::reload();
- Router::connect('/members/:controller/:action/*', array('prefix' => 'members'));
- Router::connect('/:controller/:action/*');
- Router::setRequestInfo(array(
- array('controller' => 'posts', 'action' => 'index', 'plugin' => null),
- array('base' => '', 'here' => 'posts/index', 'webroot' => '/')
- ));
- $this->Paginator->request->params['paging']['Article']['page'] = 2;
- $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
- $options = array('prefix' => 'members');
- $result = $this->Paginator->generateUrl($options);
- $expected = '/members/posts/index?page=2';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->sort('name', null, array('url' => $options));
- $expected = array(
- 'a' => array('href' => '/members/posts/index?page=2&sort=name&direction=asc'),
- 'Name',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('next', array('url' => $options));
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array('href' => '/members/posts/index?page=3', 'rel' => 'next'),
- 'next',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('prev', array('url' => $options));
- $expected = array(
- 'li' => array('class' => 'prev'),
- 'a' => array('href' => '/members/posts/index', 'rel' => 'prev'),
- 'prev',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $options = array('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 = array('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);
- }
- /**
- * testOptions method
- *
- * @return void
- */
- public function testOptions() {
- $this->Paginator->options = array();
- $this->Paginator->request->params = array();
- $options = array('paging' => array('Article' => array(
- 'direction' => 'desc',
- 'sort' => 'title'
- )));
- $this->Paginator->options($options);
- $expected = array('Article' => array(
- 'direction' => 'desc',
- 'sort' => 'title'
- ));
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- $this->Paginator->options = array();
- $this->Paginator->request->params = array();
- $options = array('Article' => array(
- 'direction' => 'desc',
- 'sort' => 'title'
- ));
- $this->Paginator->options($options);
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- $options = array('paging' => array('Article' => array(
- 'direction' => 'desc',
- 'sort' => 'Article.title'
- )));
- $this->Paginator->options($options);
- $expected = array('Article' => array(
- 'direction' => 'desc',
- 'sort' => 'Article.title'
- ));
- $this->assertEquals($expected, $this->Paginator->request->params['paging']);
- }
- /**
- * testPassedArgsMergingWithUrlOptions method
- *
- * @return void
- */
- public function testPassedArgsMergingWithUrlOptions() {
- Router::setRequestInfo(array(
- array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2')),
- array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
- ));
- $this->Paginator->request->params['paging'] = array(
- 'Article' => array(
- 'page' => 1, 'current' => 3, 'count' => 13,
- 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
- 'sort' => null, 'direction' => null,
- )
- );
- $this->Paginator->request->params['pass'] = array(2);
- $this->Paginator->request->query = array('page' => 1, 'foo' => 'bar', 'x' => 'y');
- $this->View->request = $this->Paginator->request;
- $this->Paginator = new PaginatorHelper($this->View);
- $result = $this->Paginator->sort('title');
- $expected = array(
- 'a' => array('href' => '/articles/index/2?foo=bar&x=y&sort=title&direction=asc'),
- 'Title',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array('class' => 'active')), '<a href=""', '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=2&foo=bar&x=y')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=3&foo=bar&x=y')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=4&foo=bar&x=y')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=5&foo=bar&x=y')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=6&foo=bar&x=y')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/articles/index/2?page=7&foo=bar&x=y')), '7', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next');
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array('href' => '/articles/index/2?page=2&foo=bar&x=y', '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(array(
- array('plugin' => null, 'controller' => 'articles', 'action' => 'index'),
- array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
- ));
- $this->Paginator->request->params['paging'] = array(
- 'Article' => array(
- '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 = array(
- 'li' => array('class' => 'next'),
- 'a' => array('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'] = array(
- 'Client' => array(
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- )
- );
- $result = $this->Paginator->prev('<< Previous');
- $expected = array(
- 'li' => array('class' => 'prev disabled'),
- 'a' => array('href' => ''),
- '<< Previous',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => 'Prev']);
- $expected = array(
- 'li' => array('class' => 'prev disabled'),
- 'a' => array('href' => ''),
- '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 = array(
- 'li' => array('class' => 'prev'),
- 'a' => array('href' => '/index', 'rel' => 'prev'),
- '<< Previous',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that prev() and the shared implementation underneath picks up from optins
- *
- * @return void
- */
- public function testPrevWithOptions() {
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
- 'nextPage' => false, 'pageCount' => 2,
- 'limit' => 10,
- )
- );
- $this->Paginator->options(array('url' => array(12, 'page' => 3)));
- $result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
- $expected = array(
- 'li' => array('class' => 'prev'),
- 'a' => array('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 = array(
- 'li' => array('class' => 'next'),
- 'a' => array('href' => '/index?page=2', 'rel' => 'next'),
- 'Next >>',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next >>', ['escape' => false]);
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array('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'] = array(
- 'Client' => array(
- 'page' => 5,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 5,
- )
- );
- $result = $this->Paginator->next('Next >>');
- $expected = array(
- 'li' => array('class' => 'next disabled'),
- 'a' => array('href' => ''),
- 'Next >>',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->next('Next >>', ['disabledTitle' => 'Next']);
- $expected = array(
- 'li' => array('class' => 'next disabled'),
- 'a' => array('href' => ''),
- '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'] = array(
- 'Client' => array(
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ),
- 'Server' => array(
- 'page' => 5,
- 'current' => 1,
- 'count' => 5,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 5,
- )
- );
- $result = $this->Paginator->next('Next', [
- 'model' => 'Client'
- ]);
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array('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="">Prev</a></li>';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->next('Next', [
- 'model' => 'Server'
- ]);
- $expected = '<li class="next disabled"><a href="">Next</a></li>';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->prev('Prev', [
- 'model' => 'Server'
- ]);
- $expected = array(
- 'li' => array('class' => 'prev'),
- 'a' => array('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'] = array(
- 'Client' => array(
- 'page' => 8,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- )
- );
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=10')), '10', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=11')), '11', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=12')), '12', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(array('first' => 'first', 'last' => 'last'));
- $expected = array(
- array('li' => array('class' => 'first')), array('a' => array('href' => '/index')), 'first', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=10')), '10', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=11')), '11', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=12')), '12', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array('class' => 'last')), array('a' => array('href' => '/index?page=15')), 'last', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 1,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- )
- );
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array('class' => 'active')), '<a href=""', '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 14,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- )
- );
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=10')), '10', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=11')), '11', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=12')), '12', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=13')), '13', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '14', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=15')), '15', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 2,
- 'current' => 3,
- 'count' => 27,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 9,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(array('last' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 15,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=10')), '10', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=11')), '11', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=12')), '12', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=13')), '13', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=14')), '14', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '15', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 10,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '10', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=11')), '11', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=12')), '12', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=13')), '13', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=14')), '14', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=15')), '15', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 6,
- 'current' => 15,
- 'count' => 623,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 42,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=8')), '8', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=9')), '9', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=10')), '10', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=42')), '42', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 37,
- 'current' => 15,
- 'count' => 623,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 42,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=33')), '33', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=34')), '34', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=35')), '35', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=36')), '36', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '37', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=38')), '38', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=39')), '39', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=40')), '40', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=41')), '41', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=42')), '42', '/a', '/li',
- );
- $this->assertHtml($expected, $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->assertTags($result, $expected);
- $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'] = array(
- 'Client' => array(
- 'page' => 1,
- 'current' => 10,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 3,
- )
- );
- $options = array('modulus' => 10);
- $result = $this->Paginator->numbers($options);
- $expected = array(
- array('li' => array('class' => 'active')), '<a href=""', '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(array('modulus' => 3));
- $expected = array(
- array('li' => array('class' => 'active')), '<a href=""', '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 4895,
- 'current' => 10,
- 'count' => 48962,
- 'prevPage' => 1,
- 'nextPage' => 1,
- 'pageCount' => 4897,
- )
- );
- $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4894')), '4894', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '4895', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 3;
- $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4893')), '4893', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4894')), '4894', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4895')), '4895', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 4893;
- $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4891')), '4891', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4892')), '4892', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '4893', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4894')), '4894', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4895')), '4895', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 58;
- $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=5')), '5', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=56')), '56', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=57')), '57', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '58', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=59')), '59', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=60')), '60', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4893')), '4893', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4894')), '4894', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4895')), '4895', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 5;
- $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=3')), '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '5', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=6')), '6', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=7')), '7', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4893')), '4893', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4894')), '4894', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4895')), '4895', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- $this->Paginator->request->params['paging']['Client']['page'] = 3;
- $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/index')), '1', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=2')), '2', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '3', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4')), '4', '/a', '/li',
- array('li' => array('class' => 'ellipsis')), '...', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4896')), '4896', '/a', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=4897')), '4897', '/a', '/li',
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test numbers() with routing parameters.
- *
- * @return void
- */
- public function testNumbersRouting() {
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- 'page' => 2,
- 'current' => 2,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 3,
- 'pageCount' => 3,
- )
- );
- $request = new Request();
- $request->addParams(array(
- 'controller' => 'clients', 'action' => 'index', 'plugin' => null
- ));
- $request->base = '';
- $request->here = '/clients/index?page=2';
- $request->webroot = '/';
- Router::setRequestInfo($request);
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array()), array('a' => array('href' => '/clients/index')), '1', '/a', '/li',
- array('li' => array('class' => 'active')), '<a href=""', '2', '/a', '/li',
- array('li' => array()), array('a' => array('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'] = array(
- 'Client' => array(
- 'page' => 1,
- 'current' => 3,
- 'count' => 13,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 5,
- ),
- 'Server' => array(
- '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 = array(
- 'li' => array('class' => 'first'),
- 'a' => array('href' => '/index'),
- '<<',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(2);
- $expected = array(
- '<li',
- array('a' => array('href' => '/index?page=6')), '6', '/a',
- '/li',
- '<li',
- array('a' => array('href' => '/index?page=7')), '7', '/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'] = array(
- '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 = array(
- 'li' => array('class' => 'first'),
- 'a' => array('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(array('url' => array('_full' => true)));
- $result = $this->Paginator->first();
- $expected = array(
- 'li' => ['class' => 'first'],
- array('a' => array(
- '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 = array(
- 'li' => ['class' => 'first'],
- 'a' => array('href' => '/index'),
- '<< first',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->first(2);
- $expected = array(
- '<li',
- array('a' => array('href' => '/index')), '1', '/a',
- '/li',
- '<li',
- array('a' => array('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 = array(
- 'li' => ['class' => 'last'],
- 'a' => array('href' => '/index?page=7'),
- 'last >>',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(1);
- $expected = array(
- '<li',
- 'a' => array('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 = array(
- '<li',
- array('a' => array('href' => '/index?page=6')), '6', '/a',
- '/li',
- '<li',
- array('a' => array('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'] = array(
- 'Client' => array(
- 'page' => 4,
- 'current' => 3,
- 'count' => 30,
- 'prevPage' => false,
- 'nextPage' => 2,
- 'pageCount' => 15,
- 'sort' => 'Client.name',
- 'direction' => 'DESC',
- )
- );
- $result = $this->Paginator->last();
- $expected = array(
- 'li' => ['class' => 'last'],
- 'a' => array(
- 'href' => '/index?page=15&sort=Client.name&direction=DESC',
- ),
- 'last >>', '/a',
- '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(1);
- $expected = array(
- '<li',
- array('a' => array('href' => '/index?page=15&sort=Client.name&direction=DESC')), '15', '/a',
- '/li',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Paginator->last(2);
- $expected = array(
- '<li',
- array('a' => array('href' => '/index?page=14&sort=Client.name&direction=DESC')), '14', '/a',
- '/li',
- '<li',
- array('a' => array('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'] = array(
- '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 = array(
- 'li' => array('class' => 'last'),
- 'a' => array('href' => '/index?page=5'),
- 'last',
- '/a',
- '/li'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testCounter method
- *
- * @return void
- */
- public function testCounter() {
- $this->Paginator->request->params['paging'] = array(
- 'Client' => array(
- '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(array('format' => 'pages'));
- $expected = '1 of 5';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->counter(array('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);
- }
- /**
- * 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(array(
- array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array()),
- array('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 = array('url' => array(
- 'page' => '1',
- 'sort' => 'Article.title',
- 'direction' => 'asc',
- ));
- $this->Paginator->options($test);
- $result = $this->Paginator->next('Next');
- $expected = array(
- 'li' => array('class' => 'next'),
- 'a' => array(
- '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 defaultModel() method
- *
- * @return void
- */
- public function testNoDefaultModel() {
- $this->Paginator->request = new Request();
- $this->assertNull($this->Paginator->defaultModel());
- }
- /**
- * test the numbers() method when there is only one page
- *
- * @return void
- */
- public function testWithOnePage() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- '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['paging'] = array(
- 'Article' => array(
- 'page' => 0,
- 'current' => 0,
- 'count' => 0,
- 'perPage' => 10,
- 'prevPage' => false,
- 'nextPage' => false,
- 'pageCount' => 0,
- 'limit' => 10,
- )
- );
- $result = $this->Paginator->counter(array('format' => 'pages'));
- $expected = '0 of 1';
- $this->assertEquals($expected, $result);
- }
- /**
- * Verify that no next and prev links are created for single page results
- *
- * @return void
- */
- public function testMetaPage0() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'page' => 1,
- 'prevPage' => false,
- 'nextPage' => false,
- 'pageCount' => 1,
- )
- );
- $expected = '';
- $result = $this->Paginator->meta();
- $this->assertSame($expected, $result);
- }
- /**
- * Verify that page 1 only has a next link
- *
- * @return void
- */
- public function testMetaPage1() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'page' => 1,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 2,
- )
- );
- $expected = '<link rel="next" href="http://localhost/index?page=2"/>';
- $result = $this->Paginator->meta();
- $this->assertSame($expected, $result);
- }
- /**
- * Verify that the method will append to a block
- *
- * @return void
- */
- public function testMetaPage1InlineFalse() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'page' => 1,
- 'prevPage' => false,
- 'nextPage' => true,
- 'pageCount' => 2,
- )
- );
- $expected = '<link rel="next" href="http://localhost/index?page=2"/>';
- $this->Paginator->meta(['block' => true]);
- $result = $this->View->fetch('meta');
- $this->assertSame($expected, $result);
- }
- /**
- * Verify that the last page only has a prev link
- *
- * @return void
- */
- public function testMetaPage1Last() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'page' => 2,
- 'prevPage' => true,
- 'nextPage' => false,
- 'pageCount' => 2,
- )
- );
- $expected = '<link rel="prev" href="http://localhost/index"/>';
- $result = $this->Paginator->meta();
- $this->assertSame($expected, $result);
- }
- /**
- * Verify that a page in the middle has both links
- *
- * @return void
- */
- public function testMetaPage10Last() {
- $this->Paginator->request['paging'] = array(
- 'Article' => array(
- 'page' => 5,
- 'prevPage' => true,
- 'nextPage' => true,
- 'pageCount' => 10,
- )
- );
- $expected = '<link rel="prev" href="http://localhost/index?page=4"/>';
- $expected .= '<link rel="next" href="http://localhost/index?page=6"/>';
- $result = $this->Paginator->meta();
- $this->assertSame($expected, $result);
- }
- }
|