Merge remote branch 'origin/1.3' into 2.0

Conflicts:
	cake/libs/inflector.php
	cake/libs/view/helpers/text.php
	cake/libs/view/pages/home.ctp
	cake/tests/cases/libs/view/helpers/time.test.php
This commit is contained in:
predominant 2010-04-16 23:43:28 +10:00
commit 92215e1795
22 changed files with 453 additions and 116 deletions

View file

@ -18,4 +18,4 @@
// @license MIT License (http://www.opensource.org/licenses/mit-license.php)
// +--------------------------------------------------------------------------------------------+ //
////////////////////////////////////////////////////////////////////////////////////////////////////
1.3.0-RC3
1.3.0-RC4

View file

@ -17,5 +17,5 @@
* @since CakePHP(tm) v 1.1.11.4062
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
return $config['Cake.version'] = '1.3.0-RC3';
return $config['Cake.version'] = '1.3.0-RC4';
?>

View file

@ -76,9 +76,9 @@ class PagesController extends AppController {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title = Inflector::humanize($path[$count - 1]);
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title'));
$this->set(compact('page', 'subpage', 'title_for_layout'));
$this->render(implode('/', $path));
}
}

View file

@ -376,7 +376,6 @@ class Dispatcher extends Object {
if (!$ctrlClass) {
return $controller;
}
$name = $ctrlClass;
$ctrlClass .= 'Controller';
if (class_exists($ctrlClass)) {
$controller =& new $ctrlClass();
@ -394,13 +393,10 @@ class Dispatcher extends Object {
function __loadController($params) {
$pluginName = $pluginPath = $controller = null;
if (!empty($params['plugin'])) {
$pluginName = Inflector::camelize($params['plugin']);
$pluginName = $controller = Inflector::camelize($params['plugin']);
$pluginPath = $pluginName . '.';
$this->params['controller'] = $params['plugin'];
$controller = $pluginName;
}
if (!empty($params['controller'])) {
$this->params['controller'] = $params['controller'];
$controller = Inflector::camelize($params['controller']);
}
if ($pluginPath . $controller) {

View file

@ -571,7 +571,7 @@ class CakeSession extends Object {
if (empty($_SESSION)) {
$_SESSION = array();
}
return false;
return true;
} elseif (!isset($_SESSION)) {
session_cache_limiter ("must-revalidate");
session_start();

View file

@ -907,10 +907,13 @@ class AuthComponent extends Object {
return $this->authenticate->hashPasswords($data);
}
$model =& $this->getModel();
if (is_array($data) && isset($data[$model->alias])) {
if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) {
$data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]);
if (is_array($data)) {
$model =& $this->getModel();
if(isset($data[$model->alias])) {
if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) {
$data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]);
}
}
}
return $data;

View file

@ -179,20 +179,56 @@ class Inflector {
* @access protected
*/
protected $_transliteration = array(
'/à|á|å|â/' => 'a',
'/è|é|ê|ẽ|ë/' => 'e',
'/ì|í|î/' => 'i',
'/ò|ó|ô|ø/' => 'o',
'/ù|ú|ů|û/' => 'u',
'/ç/' => 'c',
'/ñ/' => 'n',
'/ä|æ/' => 'ae',
'/ö/' => 'oe',
'/ä|æ|ǽ/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/ß/' => 'ss'
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A',
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
'/Ð|Ď|Đ/' => 'D',
'/ð|ď|đ/' => 'd',
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E',
'/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e',
'/Ĝ|Ğ|Ġ|Ģ/' => 'G',
'/ĝ|ğ|ġ|ģ/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I',
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
'/Ķ/' => 'K',
'/ķ/' => 'k',
'/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L',
'/ĺ|ļ|ľ|ŀ|ł/' => 'l',
'/Ñ|Ń|Ņ|Ň/' => 'N',
'/ñ|ń|ņ|ň|ʼn/' => 'n',
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O',
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o',
'/Ŕ|Ŗ|Ř/' => 'R',
'/ŕ|ŗ|ř/' => 'r',
'/Ś|Ŝ|Ş|Š/' => 'S',
'/ś|ŝ|ş|š|ſ/' => 's',
'/Ţ|Ť|Ŧ/' => 'T',
'/ţ|ť|ŧ/' => 't',
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U',
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u',
'/Ý|Ÿ|Ŷ/' => 'Y',
'/ý|ÿ|ŷ/' => 'y',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž/' => 'Z',
'/ź|ż|ž/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/'=> 'ss',
'/IJ/' => 'IJ',
'/ij/' => 'ij',
'/Œ/' => 'OE',
'/ƒ/' => 'f'
);
/**

View file

@ -374,7 +374,7 @@ class TreeBehavior extends ModelBehavior {
if (!is_null($overrideRecursive)) {
$recursive = $overrideRecursive;
}
$parentId = $Model->read($parent, $id);
$parentId = $Model->find('first', array('conditions' => array($Model->primaryKey => $id), 'fields' => array($parent), 'recursive' => -1));
if ($parentId) {
$parentId = $parentId[$Model->alias][$parent];

View file

@ -231,7 +231,12 @@ class DboPostgres extends DboSource {
if (!empty($c['char_length'])) {
$length = intval($c['char_length']);
} elseif (!empty($c['oct_length'])) {
$length = intval($c['oct_length']);
if ($c['type'] == 'character varying') {
$length = null;
$c['type'] = 'text';
} else {
$length = intval($c['oct_length']);
}
} else {
$length = $this->length($c['type']);
}

View file

@ -1875,7 +1875,7 @@ class Model extends Overloadable {
*
* @param mixed $conditions Conditions to match
* @param boolean $cascade Set to true to delete records that depend on this record
* @param boolean $callbacks Run callbacks (not being used)
* @param boolean $callbacks Run callbacks
* @return boolean True on success, false on failure
* @access public
* @link http://book.cakephp.org/view/1038/deleteAll

View file

@ -574,14 +574,15 @@ class Router {
}
$pluginPattern = implode('|', $plugins);
$match = array('plugin' => $pluginPattern);
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
foreach ($this->__prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
$indexParams = $params + array('action' => 'index');
$this->connect("/{$prefix}/:plugin", $indexParams, $shortParams);
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
$this->connect('/:plugin', array('action' => 'index'), $shortParams);
$this->connect('/:plugin/:controller', array('action' => 'index'), $match);
$this->connect('/:plugin/:controller/:action/*', array(), $match);
@ -769,9 +770,6 @@ class Router {
} else {
$params = end($self->__params);
}
if (isset($params['prefix']) && strpos($params['action'], $params['prefix']) === 0) {
$params['action'] = substr($params['action'], strlen($params['prefix']) + 1);
}
}
$path = array('base' => null);
@ -817,6 +815,9 @@ class Router {
} elseif (isset($url[$prefix]) && !$url[$prefix]) {
unset($url[$prefix]);
}
if (isset($url[$prefix]) && strpos($url['action'], $prefix) === 0) {
$url['action'] = substr($url['action'], strlen($prefix) + 1);
}
}
$url += array('controller' => $params['controller'], 'plugin' => $params['plugin']);
@ -1344,11 +1345,12 @@ class CakeRoute {
return;
}
$route = $this->template;
$names = $replacements = $search = array();
$names = $routeParams = array();
$parsed = preg_quote($this->template, '#');
preg_match_all('#:([A-Za-z0-9_-]+[A-Z0-9a-z])#', $route, $namedElements);
foreach ($namedElements[1] as $i => $name) {
$search = '\\' . $namedElements[0][$i];
if (isset($this->options[$name])) {
$option = null;
if ($name !== 'plugin' && array_key_exists($name, $this->defaults)) {
@ -1356,15 +1358,12 @@ class CakeRoute {
}
$slashParam = '/\\' . $namedElements[0][$i];
if (strpos($parsed, $slashParam) !== false) {
$replacements[] = '(?:/(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
$search[] = $slashParam;
$routeParams[$slashParam] = '(?:/(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
} else {
$search[] = '\\' . $namedElements[0][$i];
$replacements[] = '(?:(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
$routeParams[$search] = '(?:(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
}
} else {
$replacements[] = '(?:(?P<' . $name . '>[^/]+))';
$search[] = '\\' . $namedElements[0][$i];
$routeParams[$search] = '(?:(?P<' . $name . '>[^/]+))';
}
$names[] = $name;
}
@ -1372,7 +1371,8 @@ class CakeRoute {
$parsed = preg_replace('#/\\\\\*$#', '(?:/(?P<_args_>.*))?', $parsed);
$this->_greedy = true;
}
$parsed = str_replace($search, $replacements, $parsed);
krsort($routeParams);
$parsed = str_replace(array_keys($routeParams), array_values($routeParams), $parsed);
$this->_compiledRoute = '#^' . $parsed . '[/]*$#';
$this->keys = $names;
}

View file

@ -447,18 +447,18 @@ class Set {
$ctext = array($context['key']);
if (!is_numeric($key)) {
$ctext[] = $token;
$token = array_shift($tokens);
if (isset($items[$token])) {
$ctext[] = $token;
$item = $items[$token];
$tok = array_shift($tokens);
if (isset($items[$tok])) {
$ctext[] = $tok;
$item = $items[$tok];
$matches[] = array(
'trace' => array_merge($context['trace'], $ctext),
'key' => $token,
'key' => $tok,
'item' => $item,
);
break;
} else {
array_unshift($tokens, $token);
} elseif ($tok !== null) {
array_unshift($tokens, $tok);
}
} else {
$key = $token;

View file

@ -117,19 +117,13 @@ class TextHelper extends AppHelper {
* @access public
* @link http://book.cakephp.org/view/1469/Text#autoLinkUrls-1619
*/
public function autoLinkUrls($text, $options = array()) {
$linkOptions = 'array(';
foreach ($options as $option => $value) {
$value = var_export($value, true);
$linkOptions .= "'$option' => $value, ";
}
$linkOptions .= ')';
$text = preg_replace_callback('#(?<!href="|">)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches',
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $linkOptions . ');'), $text);
public function autoLinkUrls($text, $htmlOptions = array()) {
$options = var_export($htmlOptions, true);
$text = preg_replace_callback('#(?<!href="|">)((?:https?|ftp|nntp)://[^\s<>()]+)#i', create_function('$matches',
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $linkOptions . ');'), $text);
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $options . ');'), $text);
}
/**

View file

@ -206,17 +206,20 @@ class MediaView extends View {
'Content-Length: ' . $fileSize));
}
$this->_output();
@ob_end_clean();
$this->_clearBuffer();
while (!feof($handle) && connection_status() == 0 && !connection_aborted()) {
while (!feof($handle)) {
if (!$this->_isActive()) {
fclose($handle);
return false;
}
set_time_limit(0);
$buffer = fread($handle, $chunkSize);
echo $buffer;
@flush();
@ob_flush();
$this->_flushBuffer();
}
fclose($handle);
exit(0);
return;
}
return false;
}
@ -250,5 +253,32 @@ class MediaView extends View {
header($header, $value[$header]);
}
}
/**
* Returns true if connection is still active
* @return boolean
* @access protected
*/
function _isActive() {
return connection_status() == 0 && !connection_aborted();
}
/**
* Clears the contents of the topmost output buffer and discards them
* @return boolean
* @access protected
*/
function _clearBuffer() {
return @ob_end_clean();
}
/**
* Flushes the contents of the output buffer
* @access protected
*/
function _flushBuffer() {
@flush();
@ob_flush();
}
}
?>
?>

View file

@ -21,7 +21,7 @@ if (Configure::read() == 0):
endif;
?>
<h2><?php echo sprintf(__('Release Notes for CakePHP %s.'), Configure::version()); ?></h2>
<a href="http://cakephp.lighthouseapp.com/projects/42648/changelog-1-3-0-RC3"><?php echo __('Read the changelog'); ?> </a>
<a href="http://cakephp.lighthouseapp.com/projects/42648/changelog-1-3-0-RC4"><?php __('Read the changelog'); ?> </a>
<?php
if (Configure::read() > 0):
Debugger::checkSecurityKeys();

View file

@ -1471,7 +1471,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/add/param:value/param2:value2';
$url = 'my_plugin/my_plugin/add/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
@ -1507,7 +1507,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'admin/my_plugin/add/5/param:value/param2:value2';
$url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['plugin'], 'my_plugin');
@ -1574,48 +1574,6 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual($controller->params['plugin'], 'my_plugin');
$this->assertEqual($controller->params['action'], 'index');
$this->assertFalse(isset($controller->params['pass'][0]));
$url = 'my_plugin/my_plugin/add';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertFalse(isset($controller->params['pass'][0]));
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/my_plugin/add/0';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertTrue(isset($controller->params['pass'][0]));
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/add';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertFalse(isset($controller->params['pass'][0]));
$this->assertEqual($controller->params['controller'], 'my_plugin');
$this->assertEqual($controller->params['action'], 'add');
$this->assertEqual($controller->params['plugin'], 'my_plugin');
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/add/0';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'my_plugin');
$this->assertEqual($controller->params['plugin'], 'my_plugin');
$this->assertEqual($controller->params['action'], 'add');
$this->assertIdentical('0', $controller->params['pass'][0]);
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/add/1';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'my_plugin');
$this->assertEqual($controller->params['plugin'], 'my_plugin');
$this->assertEqual($controller->params['action'], 'add');
$this->assertIdentical('1', $controller->params['pass'][0]);
}
/**

View file

@ -561,6 +561,7 @@ class DboPostgresTest extends CakeTestCase {
$db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' (
id serial NOT NULL,
"varchar" character varying(40) NOT NULL,
"full_length" character varying NOT NULL,
"timestamp" timestamp without time zone,
date date,
CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id)
@ -573,7 +574,9 @@ class DboPostgresTest extends CakeTestCase {
));
$schema->tables = array('datatypes' => $result['tables']['datatypes']);
$result = $db1->createSchema($schema, 'datatypes');
$this->assertNoPattern('/timestamp DEFAULT/', $result);
$this->assertPattern('/\"full_length\"\s*text\s.*,/', $result);
$this->assertPattern('/timestamp\s*,/', $result);
$db1->query('DROP TABLE ' . $db1->fullTableName('datatypes'));

View file

@ -1125,7 +1125,7 @@ class RouterTest extends CakeTestCase {
Router::parse('/');
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
$expected = '/admin/test_plugin/test_plugin';
$expected = '/admin/test_plugin';
$this->assertEqual($result, $expected);
Router::reload();
@ -1149,6 +1149,12 @@ class RouterTest extends CakeTestCase {
$expected = '/admin/test_plugin/show_tickets/edit/6';
$this->assertEqual($result, $expected);
$result = Router::url(array(
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'index', 'admin' => true
));
$expected = '/admin/test_plugin/show_tickets';
$this->assertEqual($result, $expected);
App::build(array('plugins' => $paths));
}
@ -1735,7 +1741,7 @@ class RouterTest extends CakeTestCase {
Router::setRequestInfo(array(
array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null),
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
array('base' => '/', 'here' => '/', 'webroot' => '/base/')
));
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false));
@ -1743,6 +1749,32 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* test url generation with prefixes and custom routes
*
* @return void
*/
function testUrlWritingWithPrefixesAndCustomRoutes() {
Router::connect(
'/admin/login',
array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true)
);
Router::setRequestInfo(array(
array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin',
'form' => array(), 'url' => array(), 'plugin' => null
),
array('base' => '/', 'here' => '/', 'webroot' => '/')
));
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true));
$this->assertEqual($result, '/admin/login');
$result = Router::url(array('controller' => 'users', 'action' => 'login'));
$this->assertEqual($result, '/admin/login');
$result = Router::url(array('controller' => 'users', 'action' => 'admin_login'));
$this->assertEqual($result, '/admin/login');
}
/**
* testPassedArgsOrder method
*
@ -2115,6 +2147,21 @@ class CakeRouteTestCase extends CakeTestCase {
$this->assertPattern($result, '/test_plugin/posts/edit/5/name:value/nick:name');
}
/**
* test that route parameters that overlap don't cause errors.
*
* @return void
*/
function testRouteParameterOverlap() {
$route =& new CakeRoute('/invoices/add/:idd/:id', array('controller' => 'invoices', 'action' => 'add'));
$result = $route->compile();
$this->assertPattern($result, '/invoices/add/1/3');
$route =& new CakeRoute('/invoices/add/:id/:idd', array('controller' => 'invoices', 'action' => 'add'));
$result = $route->compile();
$this->assertPattern($result, '/invoices/add/1/3');
}
/**
* test compiling routes with keys that have patterns
*

View file

@ -923,7 +923,6 @@ class SetTest extends CakeTestCase {
)
)
);
$expected = array(array('Category' => $tree[1]['Category']));
$r = Set::extract('/Category[name=Category 2]', $tree);
$this->assertEqual($r, $expected);
@ -1081,6 +1080,14 @@ class SetTest extends CakeTestCase {
$r = Set::extract('/User/id', $nonZero);
$this->assertEqual($r, $expected);
$expected = array(
array('User' => array('id' => 1, 'name' => 'John')),
array('User' => array('id' => 2, 'name' => 'Bob')),
array('User' => array('id' => 3, 'name' => 'Tony')),
);
$result = Set::extract('/User', $nonZero);
$this->assertEqual($result, $expected);
$nonSequential = array(
'User' => array(
0 => array('id' => 1),
@ -1142,6 +1149,55 @@ class SetTest extends CakeTestCase {
$this->assertEqual(Set::extract('/Level1/Level2', $data), array(array('Level2' => array('test1', 'test2'))));
$this->assertEqual(Set::extract('/Level1/Level2bis', $data), array(array('Level2bis' => array('test3', 'test4'))));
}
/**
* test extract() with elements that have non-array children.
*
* @return void
*/
function testExtractWithNonArrayElements() {
$data = array(
'node' => array(
array('foo'),
'bar'
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('node' => array('foo')),
'bar'
);
$this->assertEqual($result, $expected);
$data = array(
'node' => array(
'foo' => array('bar'),
'bar' => array('foo')
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('foo' => array('bar')),
array('bar' => array('foo')),
);
$this->assertEqual($result, $expected);
$data = array(
'node' => array(
'foo' => array(
'bar'
),
'bar' => 'foo'
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('foo' => array('bar')),
'foo'
);
$this->assertEqual($result, $expected);
}
/**
* testMatches method
*

View file

@ -207,6 +207,36 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLink($text);
$expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text);
$this->assertEqual($result, $expected);
$text = 'This is a test text with URL http://www.cakephp.org and some more text';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a> and some more text';
$result = $this->Text->autoLink($text);
$this->assertEqual($result, $expected);
$text = "This is a test text with URL http://www.cakephp.org\tand some more text";
$expected = "This is a test text with URL <a href=\"http://www.cakephp.org\">http://www.cakephp.org</a>\tand some more text";
$result = $this->Text->autoLink($text);
$this->assertEqual($result, $expected);
$text = 'This is a test text with URL http://www.cakephp.org(and some more text)';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>(and some more text)';
$result = $this->Text->autoLink($text);
$this->assertEqual($result, $expected);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class'=>'link'));
$this->assertEqual($result, $expected);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link" id="MyLink">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class'=>'link', 'id'=>'MyLink'));
$this->assertEqual($result, $expected);
}
/**

View file

@ -661,9 +661,7 @@ class TimeHelperTest extends CakeTestCase {
'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS)
), true);
Configure::write('Config.language', 'time_test');
$time = 1263487419; // Thu Jan 14 11:43:39 2010
date_default_timezone_set('Etc/GMT+5');
$time = strtotime('Thu Jan 14 11:43:39 2010');
$result = $this->Time->convertSpecifiers('%a', $time);
$expected = 'jue';
@ -753,7 +751,7 @@ class TimeHelperTest extends CakeTestCase {
'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS)
), true);
Configure::write('Config.language', 'time_test');
$time = 1263495568; //Thu Jan 14 13:59:28 2010
$time = strtotime('Thu Jan 14 13:59:28 2010');
$result = $this->Time->i18nFormat($time);
$expected = '14/01/10';
@ -784,4 +782,4 @@ class TimeHelperTest extends CakeTestCase {
$this->assertEqual($this->Time->format($time, '%c'), $this->Time->i18nFormat($time, '%c'));
}
}
?>
?>

View file

@ -0,0 +1,181 @@
<?php
/**
* ThemeViewTest file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', array('Media', 'Controller'));
if (!class_exists('ErrorHandler')) {
App::import('Core', array('Error'));
}
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
/**
* ThemePostsController class
*
* @package cake
* @subpackage cake.tests.cases.libs.view
*/
class MediaController extends Controller {
/**
* name property
*
* @var string 'Media'
* @access public
*/
var $name = 'Media';
/**
* index download
*
* @access public
* @return void
*/
function download() {
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS .'css' . DS;
$id = 'test_asset.css';
$extension = 'css';
$this->set(compact('path', 'id', 'extension'));
}
}
/**
* TestMediaView class
*
* @package cake
* @subpackage cake.tests.cases.libs.view
*/
class TestMediaView extends MediaView {
/**
* headers public property as a copy from protected property _headers
*
* @var array
* @access public
*/
var $headers = array();
/**
* active property to mock the status of a remote connection
*
* @var boolean true
* @access public
*/
var $active = true;
function _output() {
$this->headers = $this->_headers;
}
/**
* _isActive method. Usted de $active property to mock an active (true) connection,
* or an aborted (false) one
*
* @access protected
* @return void
*/
function _isActive() {
return $this->active;
}
/**
* _clearBuffer method
*
* @access protected
* @return void
*/
function _clearBuffer() {
return true;
}
/**
* _flushBuffer method
*
* @access protected
* @return void
*/
function _flushBuffer() {
}
}
/**
* ThemeViewTest class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class MediaViewTest extends CakeTestCase {
/**
* startTest method
*
* @access public
* @return void
*/
function startTest() {
Router::reload();
$this->Controller =& new Controller();
$this->MediaController =& new MediaController();
$this->MediaController->viewPath = 'posts';
$this->MediaController->download();
$this->MediaView =& new TestMediaView($this->MediaController);
}
/**
* endTest method
*
* @access public
* @return void
*/
function endTest() {
unset($this->MediaView);
unset($this->MediaController);
unset($this->Controller);
ClassRegistry::flush();
}
/**
* testRender method
*
* @access public
* @return void
*/
function testRender() {
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertTrue($result !== false);
$this->assertEqual($output, 'this is the test asset css file');
}
/**
* testConnectionAborted method
*
* @access public
* @return void
*/
function testConnectionAborted() {
$this->MediaView->active = false;
$result = $this->MediaView->render();
$this->assertFalse($result);
}
}
?>