mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'local/svn/1.2.x.x' into 1.2
This commit is contained in:
commit
97e55d7bdf
17 changed files with 673 additions and 175 deletions
|
@ -362,8 +362,8 @@ if (!function_exists('array_combine')) {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -515,10 +515,10 @@ class Dispatcher extends Object {
|
|||
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 == '//') {
|
||||
|
|
|
@ -491,7 +491,6 @@ class EmailComponent extends Object{
|
|||
$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 @@ class EmailComponent extends Object{
|
|||
*/
|
||||
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;
|
||||
|
|
|
@ -481,9 +481,11 @@ class DboMysql extends DboMysqlBase {
|
|||
|
||||
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)) {
|
||||
|
|
|
@ -200,9 +200,8 @@ class DboSource extends DataSource {
|
|||
if ($this->error) {
|
||||
$this->showQuery($sql);
|
||||
return false;
|
||||
} else {
|
||||
return $this->_result;
|
||||
}
|
||||
return $this->_result;
|
||||
}
|
||||
/**
|
||||
* DataSource Query abstraction
|
||||
|
@ -1515,12 +1514,12 @@ class DboSource extends DataSource {
|
|||
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 @@ class DboSource extends DataSource {
|
|||
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 @@ class DboSource extends DataSource {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$type = (is_object($model) ? $model->getColumnType($key) : null);
|
||||
|
||||
$null = ($value === null || (is_array($value) && empty($value)));
|
||||
|
||||
if (strtolower($operator) === 'not') {
|
||||
|
@ -1917,6 +1918,7 @@ class DboSource extends DataSource {
|
|||
);
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
$value = $this->value($value, $type);
|
||||
|
||||
if ($key !== '?') {
|
||||
|
@ -1957,6 +1959,7 @@ class DboSource extends DataSource {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return "{$key} {$operator} {$value}";
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -460,8 +460,6 @@ class Router extends Object {
|
|||
|
||||
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 @@ class Router extends Object {
|
|||
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 @@ class Router extends Object {
|
|||
$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 @@ class Router extends Object {
|
|||
* @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 @@ class Router extends Object {
|
|||
}
|
||||
return $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip escape characters from parameter values.
|
||||
*
|
||||
|
|
|
@ -226,11 +226,12 @@ class PaginatorHelper extends AppHelper {
|
|||
}
|
||||
$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];
|
||||
}
|
||||
|
@ -449,9 +450,9 @@ class PaginatorHelper extends AppHelper {
|
|||
function numbers($options = array()) {
|
||||
if ($options === true) {
|
||||
$options = array(
|
||||
'before' => ' | ', 'after' => ' | ',
|
||||
'first' => 'first', 'last' => 'last',
|
||||
);
|
||||
'before' => ' | ', 'after' => ' | ',
|
||||
'first' => 'first', 'last' => 'last',
|
||||
);
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
|
@ -490,11 +491,15 @@ class PaginatorHelper extends AppHelper {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,11 +525,15 @@ class PaginatorHelper extends AppHelper {
|
|||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,10 +142,10 @@ class SessionHelper extends CakeSession {
|
|||
$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);
|
||||
|
|
|
@ -277,17 +277,20 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
|
|
@ -417,6 +417,10 @@ class View extends Object {
|
|||
*/
|
||||
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 @@ class View extends Object {
|
|||
$paths = array();
|
||||
$viewPaths = Configure::read('viewPaths');
|
||||
|
||||
if ($plugin !== null) {
|
||||
if (!empty($plugin)) {
|
||||
$count = count($viewPaths);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
|
||||
|
|
|
@ -94,11 +94,28 @@ class BasicsTest extends CakeTestCase {
|
|||
|
||||
$_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();
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ class TestTaskTest extends CakeTestCase {
|
|||
'16. setAction($action)',
|
||||
'17. validate()',
|
||||
'18. validateErrors()'
|
||||
)A
|
||||
)
|
||||
);
|
||||
$this->Shell->expectAt(1, 'out', $expected);
|
||||
|
||||
|
|
|
@ -337,7 +337,8 @@ MSGBLOC;
|
|||
|
||||
// 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 @@ HTMLBLOC;
|
|||
$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));
|
||||
|
||||
|
@ -556,6 +558,66 @@ TEXTBLOC;
|
|||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
$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
|
||||
*
|
||||
|
|
|
@ -2133,7 +2133,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$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 @@ class DboSourceTest extends CakeTestCase {
|
|||
$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 @@ class DboSourceTest extends CakeTestCase {
|
|||
'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 @@ class DboSourceTest extends CakeTestCase {
|
|||
"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)');
|
||||
|
|
|
@ -299,7 +299,7 @@ class RouterTest extends CakeTestCase {
|
|||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -116,9 +116,11 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
));
|
||||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
|
||||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testSortKey() {
|
||||
|
||||
$result = $this->Paginator->sortKey(null, array(
|
||||
'order' => array('Article.title' => 'desc'
|
||||
)));
|
||||
|
@ -200,69 +251,69 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
* @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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
*/
|
||||
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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
'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"><< Previous</div>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'div' => array('class' => 'disabled'),
|
||||
'<< Previous',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'span'));
|
||||
$expected = '<span class="disabled"><< Previous</span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'span' => array('class' => 'disabled'),
|
||||
'<< 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[^<>]+><< Previous<\/a>$/', $result);
|
||||
$this->assertPattern('/href="\/index\/page:1"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< 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[^<>]+><< Previous<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< 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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
|
||||
$this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div',
|
||||
'<strong>Disabled</strong>',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
|
||||
$this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div',
|
||||
'<strong>Disabled</strong>',
|
||||
'/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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$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'),
|
||||
'<< 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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
*/
|
||||
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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->first();
|
||||
$expected = '<span><a href="/index/page:1"><< first</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< first',
|
||||
'/a',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->first('<<', array('tag' => 'li'));
|
||||
$expected = '<li><a href="/index/page:1"><<</a></li>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<li',
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<<',
|
||||
'/a',
|
||||
'/li'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last();
|
||||
$expected = '<span><a href="/index/page:15">last >></a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
'a' => array('href' => '/index/page:15'),
|
||||
'last >>',
|
||||
'/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 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->first();
|
||||
$expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC"><< first</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a',
|
||||
'/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last();
|
||||
$expected = '<span><a href="/index/page:15/sort:Client.name/direction:DESC">last >></a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last >>', '/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
|
||||
|
@ -855,7 +1122,6 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$result = $this->Paginator->counter(array('format' => 'range'));
|
||||
$expected = '1 - 3 of 13';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
}
|
||||
/**
|
||||
* testHasPage method
|
||||
|
@ -893,23 +1159,37 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
));
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -937,7 +1217,12 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -27,6 +27,26 @@
|
|||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
if (!class_exists('AppError')) {
|
||||
App::import('Error');
|
||||
/**
|
||||
* AppController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class AppError extends ErrorHandler {
|
||||
/**
|
||||
* _stop method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function _stop() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View'));
|
||||
App::import('Helper', array('Session'));
|
||||
/**
|
||||
|
@ -143,7 +163,9 @@ class SessionHelperTest extends CakeTestCase {
|
|||
$result = ob_get_clean();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$_viewPaths = Configure::read('viewPaths');
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||
|
||||
$controller = new Controller();
|
||||
$this->Session->view = new View($controller);
|
||||
|
||||
|
@ -165,6 +187,36 @@ class SessionHelperTest extends CakeTestCase {
|
|||
$expected = 'Bare message';
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertFalse($this->Session->check('Message.bare'));
|
||||
|
||||
Configure::write('viewPaths', $_viewPaths);
|
||||
}
|
||||
/**
|
||||
* testFlash method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testFlashMissingLayout() {
|
||||
$_SESSION = array(
|
||||
'Message' => array(
|
||||
'notification' => array(
|
||||
'layout' => 'does_not_exist',
|
||||
'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
|
||||
'message' => 'This is a test of the emergency broadcasting system',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$controller = new Controller();
|
||||
$this->Session->view = new View($controller);
|
||||
|
||||
ob_start();
|
||||
$this->Session->flash('notification');
|
||||
$result = ob_get_contents();
|
||||
ob_clean();
|
||||
|
||||
$this->assertPattern("/Missing Layout/", $result);
|
||||
$this->assertPattern("/layouts\/does_not_exist.ctp/", $result);
|
||||
}
|
||||
/**
|
||||
* testID method
|
||||
|
|
Loading…
Reference in a new issue