| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994 |
- <?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\Event\Event;
- 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->assertTags($result, $expected);
- $result = $this->Paginator->sort('title', null, ['model' => 'Nope']);
- $this->assertTags($result, $expected);
- $result = $this->Paginator->sort('title', null, ['model' => 'Article']);
- $this->assertTags($result, $expected);
- $result = $this->Paginator->sort('date');
- $expected = array(
- 'a' => array('href' => '/accounts/index/param?sort=date&direction=desc', 'class' => 'asc'),
- 'Date',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Paginator->sort('title', 'TestTitle');
- $expected = array(
- 'a' => array('href' => '/accounts/index/param?sort=title&direction=asc'),
- 'TestTitle',
- '/a'
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => true]);
- $this->assertTags($result, $expected);
- $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => false]);
- $expected = array(
- 'a' => array('href' => '/index?sort=title&direction=asc'),
- 'TestTitle >',
- '/a'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $result = $this->Paginator->sort('full_name');
- $expected = array(
- 'a' => array('href' => '/accounts/index?sort=full_name&direction=desc', 'class' => 'asc'),
- 'Full Name',
- '/a'
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $result = $this->Paginator->sort('full_name');
- $expected = array(
- 'a' => array('href' => '/accounts/index?sort=full_name&direction=asc', 'class' => 'desc'),
- 'Full Name',
- '/a'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->Paginator->beforeRender(new Event('Foo.bar'), 'posts/index');
- $result = $this->Paginator->sort('title');
- $expected = array(
- 'a' => array('href' => '/articles/index/2?foo=bar&x=y&sort=title&direction=asc'),
- 'Title',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Paginator->numbers();
- $expected = array(
- array('li' => array('class' => 'active')), '<span', '1', '/span', '/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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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'),
- 'span' => array(),
- '<< Previous',
- '/span',
- '/li'
- );
- $this->assertTags($result, $expected);
- $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => 'Prev']);
- $expected = array(
- 'li' => array('class' => 'prev disabled'),
- 'span' => array(),
- 'Prev',
- '/span',
- '/li'
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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'),
- 'span' => array(),
- 'Next >>',
- '/span',
- '/li'
- );
- $this->assertTags($result, $expected);
- $result = $this->Paginator->next('Next >>', ['disabledTitle' => 'Next']);
- $expected = array(
- 'li' => array('class' => 'next disabled'),
- 'span' => array(),
- 'Next',
- '/span',
- '/li'
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $result = $this->Paginator->prev('Prev', [
- 'model' => 'Client'
- ]);
- $expected = '<li class="prev disabled"><span>Prev</span></li>';
- $this->assertEquals($expected, $result);
- $result = $this->Paginator->next('Next', [
- 'model' => 'Server'
- ]);
- $expected = '<li class="next disabled"><span>Next</span></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->assertTags($result, $expected);
- }
- /**
- * 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')), '<span', '8', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '8', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '1', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '14', '/span', '/li',
- array('li' => array()), array('a' => array('href' => '/index?page=15')), '15', '/a', '/li',
- );
- $this->assertTags($result, $expected);
- $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')), '<span', '2', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '2', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '15', '/span', '/li',
- );
- $this->assertTags($result, $expected);
- $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')), '<span', '10', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '6', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '37', '/span', '/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->assertTags($result, $expected);
- }
- /**
- * 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')), '<span', '1', '/span', '/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->assertTags($result, $expected);
- $result = $this->Paginator->numbers(array('modulus' => 3));
- $expected = array(
- array('li' => array('class' => 'active')), '<span', '1', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '4895', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '3', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '3', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '3', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '4893', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '58', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '5', '/span', '/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->assertTags($result, $expected);
- $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')), '<span', '3', '/span', '/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->assertTags($result, $expected);
- }
- /**
- * 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')), '<span', '2', '/span', '/li',
- array('li' => array()), array('a' => array('href' => '/clients/index?page=3')), '3', '/a', '/li',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * 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"><span>5</span></li>', $result);
- $this->assertNotContains('<li class="active"><span>1</span></li>', $result);
- $result = $this->Paginator->numbers(['model' => 'Client']);
- $this->assertContains('<li class="active"><span>1</span></li>', $result);
- $this->assertNotContains('<li class="active"><span>5</span></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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $result = $this->Paginator->last(1);
- $expected = array(
- '<li',
- 'a' => array('href' => '/index?page=7'),
- '7',
- '/a',
- '/li'
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- $result = $this->Paginator->last(1);
- $expected = array(
- '<li',
- array('a' => array('href' => '/index?page=15&sort=Client.name&direction=DESC')), '15', '/a',
- '/li',
- );
- $this->assertTags($result, $expected);
- $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->assertTags($result, $expected);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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);
- }
- /**
- * 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->assertTags($result, $expected);
- }
- /**
- * 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);
- }
- }
|