Browse files

Merge branch '1.2' into 1.3

  • Loading branch information...
2 parents f295a21 + 97e55d7 commit a9d98e73c358819a7fad4bbf60c93a217c917c61 gwoo committed Jul 22, 2009
View
4 cake/basics.php
@@ -362,8 +362,8 @@ function am() {
*/
function env($key) {
if ($key == 'HTTPS') {
- if (isset($_SERVER) && !empty($_SERVER)) {
- return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
+ if (isset($_SERVER['HTTPS'])) {
+ return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
}
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
}
View
4 cake/dispatcher.php
@@ -515,10 +515,10 @@ function uri() {
parse_str($uri[1], $_GET);
}
$uri = $uri[0];
- } elseif (empty($uri) && is_string(env('QUERY_STRING'))) {
+ } else {
$uri = env('QUERY_STRING');
}
- if (strpos($uri, 'index.php') !== false) {
+ if (is_string($uri) && strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
View
17 cake/libs/controller/components/email.php
@@ -491,7 +491,6 @@ function __createHeader() {
$this->__header[] = 'Content-Type: text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
- $this->__header[] = '';
}
$this->__header[] = 'Content-Transfer-Encoding: 7bit';
@@ -504,12 +503,16 @@ function __createHeader() {
*/
function __formatMessage($message) {
if (!empty($this->attachments)) {
- $prefix = array(
- '--' . $this->__boundary,
- 'Content-Type: text/plain; charset=' . $this->charset,
- 'Content-Transfer-Encoding: 7bit',
- ''
- );
+ $prefix = array('--' . $this->__boundary);
+ if ($this->sendAs === 'text') {
+ $prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
+ } elseif ($this->sendAs === 'html') {
+ $prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
+ } elseif ($this->sendAs === 'both') {
+ $prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
+ }
+ $prefix[] = 'Content-Transfer-Encoding: 7bit';
+ $prefix[] = '';
$message = array_merge($prefix, $message);
}
return $message;
View
6 cake/libs/model/datasources/dbo/dbo_mysql.php
@@ -481,9 +481,11 @@ function value($data, $column = null, $safe = false) {
if ($parent != null) {
return $parent;
- } elseif ($data === null || (is_array($data) && empty($data))) {
+ }
+ if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
- } elseif ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
+ }
+ if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
if (empty($column)) {
View
15 cake/libs/model/datasources/dbo_source.php
@@ -200,9 +200,8 @@ function execute($sql, $options = array()) {
if ($this->error) {
$this->showQuery($sql);
return false;
- } else {
- return $this->_result;
}
+ return $this->_result;
}
/**
* DataSource Query abstraction
@@ -1515,12 +1514,12 @@ function _getJoins($model) {
return $join;
}
/**
- * Returns the an SQL calculation, i.e. COUNT() or MAX()
+ * Returns an SQL calculation, i.e. COUNT() or MAX()
*
* @param model $model
* @param string $func Lowercase name of SQL function, i.e. 'count' or 'max'
* @param array $params Function parameters (any values must be quoted manually)
- * @return string An SQL calculation function
+ * @return string An SQL calculation function
* @access public
*/
function calculate(&$model, $func, $params = array()) {
@@ -1843,9 +1842,9 @@ function conditionKeysToString($conditions, $quoteValues = true, $model = null)
if (array_keys($value) === array_values(array_keys($value))) {
$count = count($value);
if ($count === 1) {
- $data = $this->name($key) . ' = (';
+ $data = $this->__quoteFields($key) . ' = (';
} else {
- $data = $this->name($key) . ' IN (';
+ $data = $this->__quoteFields($key) . ' IN (';
}
if ($quoteValues || strpos($value[0], '-!') !== 0) {
if (is_object($model)) {
@@ -1908,7 +1907,9 @@ function __parseKey($model, $key, $value) {
}
}
+
$type = (is_object($model) ? $model->getColumnType($key) : null);
+
$null = ($value === null || (is_array($value) && empty($value)));
if (strtolower($operator) === 'not') {
@@ -1917,6 +1918,7 @@ function __parseKey($model, $key, $value) {
);
return $data[0];
}
+
$value = $this->value($value, $type);
if ($key !== '?') {
@@ -1957,6 +1959,7 @@ function __parseKey($model, $key, $value) {
break;
}
}
+
return "{$key} {$operator} {$value}";
}
/**
View
9 cake/libs/router.php
@@ -460,8 +460,6 @@ function parse($url) {
if (isset($names[$key])) {
$out[$names[$key]] = $_this->stripEscape($found);
- } elseif (isset($names[$key]) && empty($names[$key]) && empty($out[$names[$key]])) {
- break;
} else {
$argOptions['context'] = array('action' => $out['action'], 'controller' => $out['controller']);
extract($_this->getArgs($found, $argOptions));
@@ -1082,7 +1080,7 @@ function __mapRoute($route, $params = array()) {
if (isset($params[$key])) {
$string = $params[$key];
unset($params[$key]);
- } else {
+ } elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
$key = $key . '/';
}
$out = str_replace(':' . $key, $string, $out);
@@ -1200,7 +1198,7 @@ function normalize($url = '/') {
$paths = Router::getPaths();
if (!empty($paths['base']) && stristr($url, $paths['base'])) {
- $url = preg_replace('/' . preg_quote($paths['base'], '/') . '/', '', $url, 1);
+ $url = preg_replace('/^' . preg_quote($paths['base'], '/') . '/', '', $url, 1);
}
$url = '/' . $url;
@@ -1245,7 +1243,7 @@ function currentRoute() {
* @access public
* @static
*/
- function stripPlugin($base, $plugin) {
+ function stripPlugin($base, $plugin = null) {
if ($plugin != null) {
$base = preg_replace('/(?:' . $plugin . ')/', '', $base);
$base = str_replace('//', '', $base);
@@ -1258,7 +1256,6 @@ function stripPlugin($base, $plugin) {
}
return $base;
}
-
/**
* Strip escape characters from parameter values.
*
View
31 cake/libs/view/helpers/paginator.php
@@ -223,11 +223,12 @@ function sort($title, $key = null, $options = array()) {
}
$dir = 'asc';
$sortKey = $this->sortKey($options['model']);
- $isSorted = ($sortKey === $key);
+ $isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
}
+
if (is_array($title) && array_key_exists($dir, $title)) {
$title = $title[$dir];
}
@@ -491,11 +492,15 @@ function numbers($options = array()) {
$end = $params['page'] + ($modulus - $params['page']) + 1;
}
- if ($first && $start > (int)$first) {
- if ($start == $first + 1) {
- $out .= $this->first($first, array('tag' => $tag, 'after' => $separator));
- } else {
- $out .= $this->first($first, array('tag' => $tag));
+ if ($first) {
+ if ($start > (int)$first) {
+ if ($start == $first + 1) {
+ $out .= $this->first($first, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
+ } else {
+ $out .= $this->first($first, array('tag' => $tag, 'separator' => $separator));
+ }
+ } elseif ($start == 2) {
+ $out .= $this->Html->tag($tag, $this->link(1, array('page' => 1), $options)) . $separator;
}
}
@@ -523,11 +528,15 @@ function numbers($options = array()) {
$out .= $after;
- if ($last && $end <= $params['pageCount'] - (int)$last) {
- if ($end + 1 == $params['pageCount']) {
- $out .= $this->last($last, array('tag' => $tag, 'before' => $separator));
- } else {
- $out .= $this->last($last, array('tag' => $tag));
+ if ($last) {
+ if ($end <= $params['pageCount'] - (int)$last) {
+ if ($end + 1 == $params['pageCount']) {
+ $out .= $this->last($last, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
+ } else {
+ $out .= $this->last($last, array('tag' => $tag, 'separator' => $separator));
+ }
+ } elseif ($end == $params['pageCount'] - 1) {
+ $out .= $separator . $this->Html->tag($tag, $this->link($params['pageCount'], array('page' => $params['pageCount']), $options));
}
}
View
8 cake/libs/view/helpers/session.php
@@ -142,10 +142,10 @@ function flash($key = 'flash') {
$out = $flash['message'];
} else {
$view =& ClassRegistry::getObject('view');
- list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle);
- list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], '');
- $out = $view->renderLayout($flash['message']);
- list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle);
+ list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle);
+ list($view->viewVars, $view->pageTitle) = array($flash['params'], '');
+ $out = $view->renderLayout($flash['message'], $flash['layout']);
+ list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle);
}
echo($out);
parent::del('Message.' . $key);
View
5 cake/libs/view/helpers/text.php
@@ -277,17 +277,20 @@ function excerpt($text, $phrase, $radius = 100, $ending = "...") {
}
$pos = strpos(strtolower($text), strtolower($phrase));
+
$startPos = 0;
if ($pos > $radius) {
$startPos = $pos - $radius;
}
+
$textLen = strlen($text);
+
$endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) {
$endPos = $textLen;
}
- $excerpt = substr($text, $startPos, $endPos - $startPos);
+ $excerpt = substr($text, $startPos, $endPos - $startPos);
if ($startPos != 0) {
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
}
View
6 cake/libs/view/view.php
@@ -417,6 +417,10 @@ function render($action = null, $layout = null, $file = null) {
*/
function renderLayout($content_for_layout, $layout = null) {
$layoutFileName = $this->_getLayoutFileName($layout);
+ if (empty($layoutFileName)) {
+ return $this->output;
+ }
+
$debug = '';
if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) {
@@ -892,7 +896,7 @@ function _paths($plugin = null, $cached = true) {
$paths = array();
$viewPaths = App::path('views');
- if ($plugin !== null) {
+ if (!empty($plugin)) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
View
17 cake/tests/cases/basics.test.php
@@ -95,11 +95,28 @@ function testEnv() {
$_SERVER = $_ENV = array();
+ $this->assertFalse(env('HTTPS'));
+
$_SERVER['HTTPS'] = 'on';
$this->assertTrue(env('HTTPS'));
+ $_SERVER['HTTPS'] = '1';
+ $this->assertTrue(env('HTTPS'));
+
+ $_SERVER['HTTPS'] = 'I am not empty';
+ $this->assertTrue(env('HTTPS'));
+
+ $_SERVER['HTTPS'] = 1;
+ $this->assertTrue(env('HTTPS'));
+
$_SERVER['HTTPS'] = 'off';
$this->assertFalse(env('HTTPS'));
+
+ $_SERVER['HTTPS'] = false;
+ $this->assertFalse(env('HTTPS'));
+
+ $_SERVER['HTTPS'] = '';
+ $this->assertFalse(env('HTTPS'));
$_SERVER = array();
View
66 cake/tests/cases/libs/controller/components/email.test.php
@@ -337,7 +337,8 @@ function testSendFormats() {
// TODO: better test for format of message sent?
$this->Controller->EmailTest->sendAs = 'both';
- $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $message);
+ $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message);
+
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
}
@@ -412,10 +413,11 @@ function testTemplates() {
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$this->Controller->EmailTest->sendAs = 'both';
- $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header);
+ $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header);
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
+
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
@@ -557,6 +559,66 @@ function testMultibyte() {
$this->assertEqual(trim($matches[1]), $subject);
}
/**
+ * undocumented function
+ *
+ * @return void
+ * @access public
+ */
+ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
+ $this->Controller->EmailTest->reset();
+ $this->Controller->EmailTest->to = 'postmaster@localhost';
+ $this->Controller->EmailTest->from = 'noreply@example.com';
+ $this->Controller->EmailTest->subject = 'Attachment Test';
+ $this->Controller->EmailTest->replyTo = 'noreply@example.com';
+ $this->Controller->EmailTest->template = null;
+ $this->Controller->EmailTest->delivery = 'debug';
+ $this->Controller->EmailTest->attachments = array(__FILE__);
+ $body = '<p>This is the body of the message</p>';
+
+ $this->Controller->EmailTest->sendAs = 'html';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+ $this->assertNoPattern('/text\/plain/', $msg);
+ $this->assertPattern('/text\/html/', $msg);
+
+ $this->Controller->EmailTest->sendAs = 'text';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+ $this->assertPattern('/text\/plain/', $msg);
+ $this->assertNoPattern('/text\/html/', $msg);
+
+ $this->Controller->EmailTest->sendAs = 'both';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+
+ $this->assertNoPattern('/text\/plain/', $msg);
+ $this->assertNoPattern('/text\/html/', $msg);
+ $this->assertPattern('/multipart\/alternative/', $msg);
+ }
+/**
+ * undocumented function
+ *
+ * @return void
+ * @access public
+ */
+ function testNoDoubleNewlinesInHeaders() {
+ $this->Controller->EmailTest->reset();
+ $this->Controller->EmailTest->to = 'postmaster@localhost';
+ $this->Controller->EmailTest->from = 'noreply@example.com';
+ $this->Controller->EmailTest->subject = 'Attachment Test';
+ $this->Controller->EmailTest->replyTo = 'noreply@example.com';
+ $this->Controller->EmailTest->template = null;
+ $this->Controller->EmailTest->delivery = 'debug';
+ $body = '<p>This is the body of the message</p>';
+
+ $this->Controller->EmailTest->sendAs = 'both';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+
+ $this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg);
+ $this->assertPattern('/\nContent-Transfer-Encoding/', $msg);
+ }
+/**
* testReset method
*
* @access public
View
18 cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -2133,7 +2133,7 @@ function testStringConditionsParsing() {
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions(array('score' => array(2=>1, 2, 10)));
- $expected = " WHERE `score` IN (1, 2, 10)";
+ $expected = " WHERE score IN (1, 2, 10)";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("Aro.rght = Aro.lft + 1.1");
@@ -2385,7 +2385,7 @@ function testArrayConditionsParsing() {
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions(array('score' => array(1, 2, 10)));
- $expected = " WHERE `score` IN (1, 2, 10)";
+ $expected = " WHERE score IN (1, 2, 10)";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions(array('score' => array()));
@@ -2476,7 +2476,7 @@ function testArrayConditionsParsing() {
'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)),
'Enrollment.yearcompleted >' => '0')
);
- $this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);
+ $this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);
$result = $this->testDb->conditions(array('id <>' => '8'));
$this->assertPattern('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result);
@@ -2495,16 +2495,24 @@ function testArrayConditionsParsing() {
"Listing.description LIKE" => "%term_2%"
);
$result = $this->testDb->conditions($conditions);
- $expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))";
+ $expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND" .
+ " ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND" .
+ " ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions(array('MD5(CONCAT(Reg.email,Reg.id))' => 'blah'));
$expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) = 'blah'";
$this->assertEqual($result, $expected);
+ $result = $this->testDb->conditions(array(
+ 'MD5(CONCAT(Reg.email,Reg.id))' => array('blah', 'blahblah')
+ ));
+ $expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) IN ('blah', 'blahblah')";
+ $this->assertEqual($result, $expected);
+
$conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76));
$result = $this->testDb->conditions($conditions);
- $expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
+ $expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$this->assertEqual($result, $expected);
$conditions = array('title' => 'user(s)');
View
55 cake/tests/cases/libs/router.test.php
@@ -299,7 +299,7 @@ function testUrlNormalization() {
$result = Router::normalize('/recipe/recipes/add');
$this->assertEqual($result, '/recipe/recipes/add');
- Router::setRequestInfo(array(array(), array('base' => 'us')));
+ Router::setRequestInfo(array(array(), array('base' => '/us')));
$result = Router::normalize('/us/users/logout/');
$this->assertEqual($result, '/users/logout');
@@ -309,6 +309,22 @@ function testUrlNormalization() {
$result = Router::normalize('/cake_12/users/logout/');
$this->assertEqual($result, '/users/logout');
+ Router::reload();
+ $_back = Configure::read('App.baseUrl');
+ Configure::write('App.baseUrl', '/');
+
+ Router::setRequestInfo(array(array(), array('base' => '/')));
+ $result = Router::normalize('users/login');
+ $this->assertEqual($result, '/users/login');
+ Configure::write('App.baseUrl', $_back);
+
+ Router::reload();
+ Router::setRequestInfo(array(array(), array('base' => 'beer')));
+ $result = Router::normalize('beer/admin/beers_tags/add');
+ $this->assertEqual($result, '/admin/beers_tags/add');
+
+ $result = Router::normalize('/admin/beers_tags/add');
+ $this->assertEqual($result, '/admin/beers_tags/add');
}
/**
* testUrlGeneration method
@@ -1036,6 +1052,28 @@ function testAdminRouting() {
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
$expected = '/beheer/posts/index/0?var=test&var2=test2';
$this->assertEqual($result, $expected);
+
+ Configure::write('Routing.admin', 'admin');
+ $paths = Configure::read('pluginPaths');
+ Configure::write('pluginPaths', array(
+ TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
+ ));
+ Configure::write('__objects.plugin', array('test_plugin'));
+
+ Router::reload();
+ Router::setRequestInfo(array(
+ array('admin' => true, 'controller' => 'controller', 'action' => 'action',
+ 'form' => array(), 'url' => array(), 'plugin' => null),
+ array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(),
+ 'argSeparator' => ':', 'namedArgs' => array())
+ ));
+ Router::parse('/');
+
+ $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
+ $expected = '/admin/test_plugin';
+ $this->assertEqual($result, $expected);
+
+ Configure::write('pluginPaths', $paths);
}
/**
* testExtensionParsingSetting method
@@ -1617,5 +1655,20 @@ function testRegexRouteMatching() {
$expected = '/test/test_another_action/locale:badness';
$this->assertEqual($result, $expected);
}
+/**
+ * testStripPlugin
+ *
+ * @return void
+ * @access public
+ */
+ function testStripPlugin() {
+ $pluginName = 'forums';
+ $url = 'example.com/' . $pluginName . '/';
+ $expected = 'example.com';
+
+ $this->assertEqual(Router::stripPlugin($url, $pluginName), $expected);
+ $this->assertEqual(Router::stripPlugin($url), $url);
+ $this->assertEqual(Router::stripPlugin($url, null), $url);
+ }
}
?>
View
527 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -116,9 +116,11 @@ function testDisabledLink() {
$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);
+ $result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
+ $expected = array(
+ 'span' => array('class' => 'disabled'), 'prev', '/span'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testSortLinks method
@@ -135,24 +137,60 @@ function testSortLinks() {
));
$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);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->sort('date');
- $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc">Date<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc'),
+ 'Date',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$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);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
+ 'TestTitle',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
- $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">ascending<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
+ 'ascending',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$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);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc'),
+ 'descending',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('title');
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
+
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('title');
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result);
}
/**
* testSortLinksUsingDotNotation method
@@ -170,16 +208,30 @@ function testSortLinksUsingDotNotation() {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Title','Article.title');
- $this->assertPattern('/\/accounts\/index\/page:1\/sort:Article.title\/direction:asc">Title<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sort('Title','Article.title');
- $this->assertPattern('/\/accounts\/index\/page:1\/sort:Article.title\/direction:desc">Title<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
$result = $this->Paginator->sort('title');
- $this->assertPattern('/\/accounts\/index\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
-
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/page:1/sort:title/direction:asc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testSortKey method
@@ -188,7 +240,6 @@ function testSortLinksUsingDotNotation() {
* @return void
*/
function testSortKey() {
-
$result = $this->Paginator->sortKey(null, array(
'order' => array('Article.title' => 'desc'
)));
@@ -200,69 +251,69 @@ function testSortKey() {
* @access public
* @return void
*/
- function testSortDir() {
- $result = $this->Paginator->sortDir();
- $expected = 'asc';
+ function testSortDir() {
+ $result = $this->Paginator->sortDir();
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
- $result = $this->Paginator->sortDir();
- $expected = 'desc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'desc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->Paginator->params['paging']['Article']['options']);
+ unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
- $result = $this->Paginator->sortDir();
- $expected = 'asc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->Paginator->params['paging']['Article']['options']);
+ unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'desc');
- $result = $this->Paginator->sortDir();
- $expected = 'desc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'desc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->Paginator->params['paging']['Article']['options']);
+ unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'asc');
- $result = $this->Paginator->sortDir();
- $expected = 'asc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->Paginator->params['paging']['Article']['options']);
+ unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['direction'] = 'asc';
- $result = $this->Paginator->sortDir();
- $expected = 'asc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->paginator->params['paging']['article']['options']);
+ unset($this->paginator->params['paging']['article']['options']);
$this->Paginator->params['paging']['Article']['options']['direction'] = 'desc';
- $result = $this->Paginator->sortDir();
- $expected = 'desc';
+ $result = $this->Paginator->sortDir();
+ $expected = 'desc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- unset($this->Paginator->params['paging']['Article']['options']);
- $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
- $expected = 'asc';
+ unset($this->Paginator->params['paging']['Article']['options']);
+ $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
- $expected = 'desc';
+ $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
+ $expected = 'desc';
- $this->assertEqual($result, $expected);
+ $this->assertEqual($result, $expected);
- $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
- $expected = 'asc';
+ $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
+ $expected = 'asc';
- $this->assertEqual($result, $expected);
- }
+ $this->assertEqual($result, $expected);
+ }
/**
* testSortAdminLinks method
*
@@ -280,8 +331,12 @@ function testSortAdminLinks() {
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);
+ $expected = array(
+ 'a' => array('href' => '/admin/users/index/page:2'),
+ 'Next',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
Router::reload();
Router::setRequestInfo(array(
@@ -291,12 +346,21 @@ function testSortAdminLinks() {
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);
+ $expected = array(
+ 'a' => array('href' => '/admin/test/index/param/page:1/sort:title/direction:asc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('Title', 'Article.title');
- $this->assertPattern('/\/admin\/test\/index\/param\/page:1\/sort:Article.title\/direction:asc"\s*>Title<\/a>$/', $result);
-
+ $expected = array(
+ 'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'),
+ 'Title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testUrlGeneration method
@@ -306,8 +370,12 @@ function testSortAdminLinks() {
*/
function testUrlGeneration() {
$result = $this->Paginator->sort('controller');
- $this->assertPattern('/\/page:1\//', $result);
- $this->assertPattern('/\/sort:controller\//', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:1/sort:controller/direction:asc'),
+ 'Controller',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->url();
$this->assertEqual($result, '/index/page:1');
@@ -351,16 +419,28 @@ function testUrlGenerationWithPrefixes() {
$this->assertEqual($result, $expected);
$result = $this->Paginator->sort('name', null, array('url' => $options));
- $expected = '<a href="/members/posts/index/page:2/sort:name/direction:asc">Name</a>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ 'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
+ 'Name',
+ '/a'
+ );
+ $this->assertTags($result, $expected, true);
$result = $this->Paginator->next('next', array('url' => $options));
- $expected = '<a href="/members/posts/index/page:3">next</a>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ 'a' => array('href' => '/members/posts/index/page:3'),
+ 'next',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->prev('prev', array('url' => $options));
- $expected = '<a href="/members/posts/index/page:1">prev</a>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ 'a' => array('href' => '/members/posts/index/page:1'),
+ 'prev',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
$result = $this->Paginator->url($options);
@@ -432,28 +512,54 @@ function testPagingLinks() {
'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);
+ $expected = array(
+ 'div' => array('class' => 'disabled'),
+ '&lt;&lt; Previous',
+ '/div'
+ );
+ $this->assertTags($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);
+ $expected = array(
+ 'span' => array('class' => 'disabled'),
+ '&lt;&lt; Previous',
+ '/span'
+ );
+ $this->assertTags($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);
+ $expected = array(
+ 'a' => array('href' => '/index/page:1'),
+ '&lt;&lt; Previous',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->next('Next');
- $this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);
- $this->assertPattern('/href="\/index\/page:3"/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:3'),
+ 'Next',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', array('escape' => true));
- $this->assertPattern('/^<a[^<>]+>&lt;&lt; Previous<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:1'),
+ '&lt;&lt; Previous',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', array('escape' => false));
- $this->assertPattern('/^<a[^<>]+><< Previous<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:1'),
+ 'preg:/<< Previous/',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging'] = array('Client' => array(
'page' => 1, 'current' => 1, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
@@ -462,13 +568,28 @@ function testPagingLinks() {
);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
- $this->assertPattern('/^<div>&lt;strong&gt;Disabled&lt;\/strong&gt;<\/div>$/', $result);
+ $expected = array(
+ '<div',
+ '&lt;strong&gt;Disabled&lt;/strong&gt;',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
- $this->assertPattern('/^<div>&lt;strong&gt;Disabled&lt;\/strong&gt;<\/div>$/', $result);
+ $expected = array(
+ '<div',
+ '&lt;strong&gt;Disabled&lt;/strong&gt;',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
- $this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
+ $expected = array(
+ '<div',
+ '<strong', 'Disabled', '/strong',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging'] = array('Client' => array(
'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
@@ -479,10 +600,20 @@ function testPagingLinks() {
$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('/\/sort:Client.name\/direction:DESC"/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC'),
+ '&lt;&lt; Previous',
+ '/a'
+ );
+ $this->assertTags($result, $expected, true);
$result = $this->Paginator->next('Next');
- $this->assertPattern('/\/sort:Client.name\/direction:DESC"/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC'),
+ 'Next',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging'] = array('Client' => array(
'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true, 'nextPage' => false, 'pageCount' => 2,
@@ -520,11 +651,16 @@ function testPagingLinksNotDefaultModel() {
)
);
$result = $this->Paginator->next('Next', array('model' => 'Client'));
- $this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);
- $this->assertPattern('/href="\/index\/page:2"/', $result); // These is passed.
+ $expected = array(
+ 'a' => array('href' => '/index/page:2'), 'Next', '/a'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
- $this->assertPattern('/^<div>No Next<\/div>$/', $result);
+ $expected = array(
+ '<div', 'No Next', '/div'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testGenericLinks method
@@ -534,24 +670,30 @@ function testPagingLinksNotDefaultModel() {
*/
function testGenericLinks() {
$result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
- $this->assertPattern('/^<a href=".+"[^<>]*>Sort by title on page 5<\/a>$/', $result);
- $this->assertPattern('/\/page:5/', $result);
- $this->assertPattern('/\/sort:title/', $result);
- $this->assertPattern('/\/direction:desc/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
+ 'Sort by title on page 5',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging']['Article']['options']['page'] = 2;
$result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
- $this->assertPattern('/^<a href=".+"[^<>]*>Sort by title<\/a>$/', $result);
- $this->assertPattern('/\/page:2/', $result);
- $this->assertPattern('/\/sort:title/', $result);
- $this->assertPattern('/\/direction:desc/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
+ 'Sort by title',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging']['Article']['options']['page'] = 4;
$result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
- $this->assertPattern('/^<a href=".+"[^<>]*>Sort by title on page 4<\/a>$/', $result);
- $this->assertPattern('/\/page:4/', $result);
- $this->assertPattern('/\/sort:Article.title/', $result);
- $this->assertPattern('/\/direction:desc/', $result);
+ $expected = array(
+ 'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
+ 'Sort by title on page 4',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
}
/**
* Tests generation of generic links with preset options
@@ -725,6 +867,66 @@ function testNumbers() {
$result = $this->Paginator->numbers();
$expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC">1</a></span> | <span class="current">2</span> | <span><a href="/index/page:3/sort:Client.name/direction:DESC">3</a></span> | <span><a href="/index/page:4/sort:Client.name/direction:DESC">4</a></span>';
$this->assertEqual($result, $expected);
+
+ $this->Paginator->params['paging'] = array('Client' => array(
+ 'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
+ 'defaults' => array('limit' => 10),
+ 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
+ );
+
+ $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
+ $expected = array(
+ array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
+ '...',
+ array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
+ ' | ',
+ array('span' => array('class' => 'current')), '4895', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
+ );
+ $this->assertTags($result, $expected);
+
+ $this->Paginator->params['paging'] = array('Client' => array(
+ 'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
+ 'defaults' => array('limit' => 10),
+ 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
+ );
+
+ $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
+ $expected = array(
+ array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
+ ' | ',
+ array('span' => array('class' => 'current')), '3', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
+ '...',
+ array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
+ ' | ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
+ $expected = array(
+ array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
+ ' - ',
+ array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
+ ' - ',
+ array('span' => array('class' => 'current')), '3', '/span',
+ ' - ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
+ '...',
+ array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
+ ' - ',
+ array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
+ );
+ $this->assertTags($result, $expected);
}
/**
* testFirstAndLast method
@@ -750,28 +952,71 @@ function testFirstAndLast() {
);
$result = $this->Paginator->first();
- $expected = '<span><a href="/index/page:1">&lt;&lt; first</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '<span',
+ 'a' => array('href' => '/index/page:1'),
+ '&lt;&lt; first',
+ '/a',
+ '/span'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->first('<<', array('tag' => 'li'));
- $expected = '<li><a href="/index/page:1">&lt;&lt;</a></li>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '<li',
+ 'a' => array('href' => '/index/page:1'),
+ '&lt;&lt;',
+ '/a',
+ '/li'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last();
- $expected = '<span><a href="/index/page:15">last &gt;&gt;</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '<span',
+ 'a' => array('href' => '/index/page:15'),
+ 'last &gt;&gt;',
+ '/a',
+ '/span'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last(1);
- $expected = '...<span><a href="/index/page:15">15</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '...',
+ '<span',
+ 'a' => array('href' => '/index/page:15'),
+ '15',
+ '/a',
+ '/span'
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last(2);
- $expected = '...<span><a href="/index/page:14">14</a></span> | <span><a href="/index/page:15">15</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '...',
+ '<span',
+ array('a' => array('href' => '/index/page:14')), '14', '/a',
+ '/span',
+ ' | ',
+ '<span',
+ array('a' => array('href' => '/index/page:15')), '15', '/a',
+ '/span',
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('tag' => 'li'));
- $expected = '...<li><a href="/index/page:14">14</a></li> | <li><a href="/index/page:15">15</a></li>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '...',
+ '<li',
+ array('a' => array('href' => '/index/page:14')), '14', '/a',
+ '/li',
+ ' | ',
+ '<li',
+ array('a' => array('href' => '/index/page:15')), '15', '/a',
+ '/li',
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->params['paging'] = array('Client' => array(
'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
@@ -789,20 +1034,42 @@ function testFirstAndLast() {
);
$result = $this->Paginator->first();
- $expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC">&lt;&lt; first</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '<span',
+ array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '&lt;&lt; first', '/a',
+ '/span',
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last();
- $expected = '<span><a href="/index/page:15/sort:Client.name/direction:DESC">last &gt;&gt;</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '<span',
+ array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last &gt;&gt;', '/a',
+ '/span',
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last(1);
- $expected = '...<span><a href="/index/page:15/sort:Client.name/direction:DESC">15</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '...',
+ '<span',
+ array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
+ '/span',
+ );
+ $this->assertTags($result, $expected);
$result = $this->Paginator->last(2);
- $expected = '...<span><a href="/index/page:14/sort:Client.name/direction:DESC">14</a></span> | <span><a href="/index/page:15/sort:Client.name/direction:DESC">15</a></span>';
- $this->assertEqual($result, $expected);
+ $expected = array(
+ '...',
+ '<span',
+ array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
+ '/span',
+ ' | ',
+ '<span',
+ array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
+ '/span',
+ );
+ $this->assertTags($result, $expected);
}
/**
* testCounter method
@@ -862,7 +1129,6 @@ function testCounter() {
$result = $this->Paginator->counter(array('format' => 'range'));
$expected = '1 - 3 of 13';
$this->assertEqual($result, $expected);
-
}
/**
* testHasPage method
@@ -900,23 +1166,37 @@ function testWithPlugin() {
));
$result = $this->Paginator->link('Page 3', array('page' => 3));
- $this->assertPattern('/["\']\/my_plugin\/magazines\/index\/page:3["\']/', $result);
+ $expected = array(
+ 'a' => array('href' => '/my_plugin/magazines/index/page:3'), 'Page 3', '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('action' => 'another_index')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
- $this->assertPattern('/["\']\/my_plugin\/magazines\/another_index\/page:3["\']/', $result);
+ $expected = array(
+ 'a' => array('href' => '/my_plugin/magazines/another_index/page:3'), 'Page 3', '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('controller' => 'issues')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
- $this->assertPattern('/["\']\/my_plugin\/issues\/index\/page:3["\']/', $result);
+ $expected = array(
+ 'a' => array('href' => '/my_plugin/issues/index/page:3'), 'Page 3', '/a'
+ );
+ $this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('plugin' => null)));
$result = $this->Paginator->link('Page 3', array('page' => 3));
- $this->assertPattern('/["\']\/magazines\/index\/page:3["\']/', $result);
+ $expected = array(
+ 'a' => array('/magazines/index/page:3'), 'Page 3', '/a'
+ );
$this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
- $this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
+ $expected = array(
+ 'a' => array('href' => '/issues/index/page:3'), 'Page 3', '/a'
+ );
+ $this->assertTags($result, $expected);
}
/**
@@ -944,7 +1224,12 @@ function testNextLinkUsingDotNotation() {
$this->Paginator->options($test);
$result = $this->Paginator->next('Next');
- $this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
+ $expected = array(
+ 'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc'),
+ 'Next',
+ '/a'
+ );
+ $this->assertTags($result, $expected);
}
}
?>

0 comments on commit a9d98e7

Please sign in to comment.