paginator.test.php

来自「Cake Framwork , Excellent」· PHP 代码 · 共 534 行 · 第 1/2 页

PHP
534
字号
<?php/* SVN FILE: $Id: paginator.test.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * Copyright 2005-2008, Cake Software Foundation, Inc. *								1785 E. Sahara Avenue, Suite 490-204 *								Las Vegas, Nevada 89104 * *  Licensed under The Open Group Test Suite License *  Redistributions of files must retain the above copyright notice. * * @filesource * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc. * @link				https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package			cake.tests * @subpackage		cake.tests.cases.libs.view.helpers * @since			CakePHP(tm) v 1.2.0.4206 * @version			$Revision: 7118 $ * @modifiedby		$LastChangedBy: gwoo $ * @lastmodified	$Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license			http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */uses('view'.DS.'helpers'.DS.'app_helper', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form',	'view'.DS.'helpers'.DS.'ajax', 'view'.DS.'helpers'.DS.'javascript', 'view'.DS.'helpers'.DS.'paginator');/** * Short description for class. * * @package		cake.tests * @subpackage	cake.tests.cases.libs.view.helpers */class PaginatorTest extends UnitTestCase {/** * setUp method *  * @access public * @return void */	function setUp() {		$this->Paginator = new PaginatorHelper();		$this->Paginator->params['paging'] = array(			'Article' => array(				'current' => 9,				'count' => 62,				'prevPage' => false,				'nextPage' => true,				'pageCount' => 7,				'defaults' => array(					'order' => 'Article.date ASC',					'limit' => 9,					'conditions' => array()                ),				'options' => array(					'order' => 'Article.date ASC',					'limit' => 9,					'page' => 1,					'conditions' => array()				)			)		);		$this->Paginator->Html =& new HtmlHelper();		$this->Paginator->Ajax =& new AjaxHelper();		$this->Paginator->Ajax->Html =& new HtmlHelper();		$this->Paginator->Ajax->Javascript =& new JavascriptHelper();		$this->Paginator->Ajax->Form =& new FormHelper();		Configure::write('Routing.admin', '');		Router::reload();	}/** * testHasPrevious method *  * @access public * @return void */	function testHasPrevious() {		$this->assertIdentical($this->Paginator->hasPrev(), false);		$this->Paginator->params['paging']['Article']['prevPage'] = true;		$this->assertIdentical($this->Paginator->hasPrev(), true);		$this->Paginator->params['paging']['Article']['prevPage'] = false;	}/** * testHasNext method *  * @access public * @return void */	function testHasNext() {		$this->assertIdentical($this->Paginator->hasNext(), true);		$this->Paginator->params['paging']['Article']['nextPage'] = false;		$this->assertIdentical($this->Paginator->hasNext(), false);		$this->Paginator->params['paging']['Article']['nextPage'] = true;	}/** * testDisabledLink method *  * @access public * @return void */	function testDisabledLink() {		$this->Paginator->params['paging']['Article']['nextPage'] = false;		$this->Paginator->params['paging']['Article']['page'] = 1;		$result = $this->Paginator->next('Next', array(), true);		$expected = '<div>Next</div>';		$this->assertEqual($result, $expected);				$this->Paginator->params['paging']['Article']['prevPage'] = false;		$result = $this->Paginator->prev('prev', array('update'=> 'theList', 'indicator'=> 'loading', 'url'=> array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));		$expected = '<span class="disabled">prev</span>';		$this->assertEqual($result, $expected);	}/** * testSortLinks method *  * @access public * @return void */	function testSortLinks() {		Router::reload();		Router::parse('/');		Router::setRequestInfo(array(			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),			array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())		));		$this->Paginator->options(array('url' => array('param')));		$result = $this->Paginator->sort('title');		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);		$result = $this->Paginator->sort('date');		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc">Date<\/a>$/', $result);		$result = $this->Paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list'));		$this->assertPattern('/\/projects\/sort\/page:2/', $result);		$this->assertPattern('/<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*Event.observe/', $result);		$result = $this->Paginator->sort('TestTitle', 'title');		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">TestTitle<\/a>$/', $result);		$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">ascending<\/a>$/', $result);		$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';		$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result);	}/** * testSortAdminLinks method *  * @access public * @return void */	function testSortAdminLinks() {		Configure::write('Routing.admin', 'admin');				Router::reload();		Router::setRequestInfo(array(			array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users'), 'form' => array()),			array('base' => '', 'here' => '/admin/users', 'webroot' => '/')		));		Router::parse('/admin/users');		$this->Paginator->params['paging']['Article']['page'] = 1;		$result = $this->Paginator->next('Next');		$this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);		$this->assertPattern('/href="\/admin\/users\/index\/page:2"/', $result);				Router::reload();		Router::setRequestInfo(array(			array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/test')),			array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/test', 'webroot' => '/')		));		Router::parse('/');		$this->Paginator->options(array('url' => array('param')));		$result = $this->Paginator->sort('title');		$this->assertPattern('/\/admin\/test\/index\/param\/page:1\/sort:title\/direction:asc"\s*>Title<\/a>$/', $result);	}/** * testUrlGeneration method *  * @access public * @return void */	function testUrlGeneration() {		$result = $this->Paginator->sort('controller');		$this->assertPattern('/\/page:1\//', $result);		$this->assertPattern('/\/sort:controller\//', $result);		$result = $this->Paginator->url();		$this->assertEqual($result, '/index/page:1');		$this->Paginator->params['paging']['Article']['options']['page'] = 2;		$result = $this->Paginator->url();		$this->assertEqual($result, '/index/page:2');				$options = array('order' => array('Article' => 'desc'));		$result = $this->Paginator->url($options);		$this->assertEqual($result, '/index/page:2/sort:Article/direction:desc');			}	/** * testOptions method *  * @access public * @return void */	function testOptions() {		$this->Paginator->options('myDiv');		$this->assertEqual('myDiv', $this->Paginator->options['update']);		$this->Paginator->options = array();		$this->Paginator->params = array();		$options = array('paging' => array('Article' => array(			'order' => 'desc',			'sort' => 'title'								)));		$this->Paginator->options($options);		$expected = array('Article' => array(			'order' => 'desc',			'sort' => 'title'		));		$this->assertEqual($expected, $this->Paginator->params['paging']);		$this->Paginator->options = array();		$this->Paginator->params = array();		$options = array('Article' => array(			'order' => 'desc',			'sort' => 'title'								));		$this->Paginator->options($options);		$this->assertEqual($expected, $this->Paginator->params['paging']);	}/** * testPagingLinks method *  * @access public * @return void */	function testPagingLinks() {		$this->Paginator->params['paging'] = array('Client' => array(			'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,			'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),			'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))		);		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));		$expected = '<div class="disabled">&lt;&lt; Previous</div>';		$this->assertEqual($result, $expected);				$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'span'));		$expected = '<span class="disabled">&lt;&lt; Previous</span>';		$this->assertEqual($result, $expected);		$this->Paginator->params['paging']['Client']['page'] = 2;		$this->Paginator->params['paging']['Client']['prevPage'] = true;		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));		$this->assertPattern('/^<a[^<>]+>&lt;&lt; Previous<\/a>$/', $result);		$this->assertPattern('/href="\/index\/page:1"/', $result);		$result = $this->Paginator->next('Next');		$this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);		$this->assertPattern('/href="\/index\/page:3"/', $result);	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?