Merge branch '1.3' into merger

Conflicts:
	cake/console/error.php
	cake/libs/cache/memcache.php
	cake/libs/cake_session.php
	cake/libs/controller/components/request_handler.php
	cake/libs/model/cake_schema.php
	cake/libs/router.php
	cake/libs/set.php
	cake/libs/view/helpers/form.php
	cake/libs/view/helpers/text.php
	cake/libs/view/view.php
	cake/tests/cases/libs/set.test.php
This commit is contained in:
mark_story 2011-01-18 20:04:30 -05:00
commit dca3fecfed
19 changed files with 280 additions and 66 deletions

View file

@ -300,10 +300,21 @@ if (!function_exists('sortByKey')) {
break;
case 'HTTP_BASE':
$host = env('HTTP_HOST');
if (substr_count($host, '.') !== 1) {
return preg_replace('/^([^.])*/i', null, env('HTTP_HOST'));
}
$parts = explode('.', $host);
$count = count($parts);
if ($count === 1) {
return '.' . $host;
} elseif ($count === 2) {
return '.' . $host;
} elseif ($count === 3) {
$gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx');
if (in_array($parts[1], $gTLD)) {
return '.' . $host;
}
}
array_shift($parts);
return '.' . implode('.', $parts);
break;
}
return null;

View file

@ -20,7 +20,7 @@
*/
?>
<?php echo '<?php' . "\n"; ?>
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:m:s') . " : ". time(); ?> */
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:i:s') . " : ". time(); ?> */
class <?php echo $model; ?>Fixture extends CakeTestFixture {
public $name = '<?php echo $model; ?>';
<?php if ($table): ?>

View file

@ -18,7 +18,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n";
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n";
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n";
?>
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');

View file

@ -116,8 +116,7 @@ class MemcacheEngine extends CacheEngine {
/**
* Write data for key into cache. When using memcache as your cache engine
* remember that the Memcache pecl extension does not support cache expiry times greater
* than 30 days in the future. If you wish to create cache entries that do not expire, set the duration
* to `0` in your cache configuration.
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
@ -126,6 +125,9 @@ class MemcacheEngine extends CacheEngine {
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
if ($duration > 30 * DAY) {
$duration = 0;
}
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
}

View file

@ -132,6 +132,7 @@ class RequestHandlerComponent extends Component {
}
}
}
$this->params = $controller->params;
$this->_set($settings);
}
@ -585,7 +586,9 @@ class RequestHandlerComponent extends Component {
}
if ($cType != null) {
if (empty($this->request->params['requested'])) {
$this->response->type($cType);
}
if (!empty($options['charset'])) {
$this->response->charset($options['charset']);

View file

@ -365,7 +365,7 @@ class CakeSchema extends Object {
$out .= "}\n";
$file = new SplFileObject($path . DS . $file, 'w+');
$content = "<?php \n/* {$name} schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
$content = "<?php \n/* {$name} schema generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n{$out}?>";
if ($file->fwrite($content)) {
return $content;
}

View file

@ -173,7 +173,7 @@ class CakeRoute {
/**
* Checks to see if the given URL can be parsed by this route.
* If the route can be parsed an array of parameters will be returned if not
* If the route can be parsed an array of parameters will be returned; if not
* false will be returned. String urls are parsed if they match a routes regular expression.
*
* @param string $url The url to attempt to parse.
@ -245,8 +245,8 @@ class CakeRoute {
}
/**
* Attempt to match a url array. If the url matches the route parameters + settings, then
* return a generated string url. If the url doesn't match the route parameters false will be returned.
* Attempt to match a url array. If the url matches the route parameters and settings, then
* return a generated string url. If the url doesn't match the route parameters, false will be returned.
* This method handles the reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.

View file

@ -221,21 +221,25 @@ class Router {
* Shows connecting a route with custom route parameters as well as providing patterns for those parameters.
* Patterns for routing parameters do not need capturing groups, as one will be added for each route params.
*
* $options offers two 'special' keys. `pass` and `persist` have special meaning in the $options array.
* $options offers three 'special' keys. `pass`, `persist` and `routeClass` have special meaning in the $options array.
*
* `pass` is used to define which of the routed parameters should be shifted into the pass array. Adding a
* parameter to pass will remove it from the regular route array. Ex. `'pass' => array('slug')`
*
* `persist` is used to define which route parameters should be automatically included when generating
* new urls. You can override peristent parameters by redifining them in a url or remove them by
* new urls. You can override persistent parameters by redefining them in a url or remove them by
* setting the parameter to `false`. Ex. `'persist' => array('lang')`
*
* `routeClass` is used to extend and change how individual routes parse requests and handle reverse routing,
* via a custom routing class. Ex. `'routeClass' => 'SlugRoute'`
*
* @param string $route A string describing the template of the route
* @param array $defaults An array describing the default route parameters. These parameters will be used by default
* and can supply routing parameters that are not dynamic. See above.
* @param array $options An array matching the named elements in the route to regular expressions which that
* element should match. Also contains additional parameters such as which routed parameters should be
* shifted into the passed arguments. As well as supplying patterns for routing parameters.
* shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
* custom routing class.
* @see routes
* @return array Array of routes
* @throws RouterException
@ -731,7 +735,7 @@ class Router {
*
* @param $which A zero-based array index representing the route to move. For example,
* if 3 routes have been added, the last route would be 2.
* @return boolean Retuns false if no route exists at the position specified by $which.
* @return boolean Returns false if no route exists at the position specified by $which.
*/
public static function promote($which = null) {
if ($which === null) {
@ -752,7 +756,7 @@ class Router {
* Returns an URL pointing to a combination of controller and action. Param
* $url can be:
*
* - Empty - the method will find address to actuall controller/action.
* - Empty - the method will find address to actual controller/action.
* - '/' - the method will find base URL of application.
* - A combination of controller/action - the method will find url for it.
*
@ -1068,7 +1072,7 @@ class Router {
}
/**
* Reverses a parsed parameter array into a string. Works similarily to Router::url(), but
* Reverses a parsed parameter array into a string. Works similarly to Router::url(), but
* Since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys.
* Those keys need to be specially handled in order to reverse a params array into a string url.
*
@ -1199,7 +1203,7 @@ class Router {
}
/**
* Takes an passed params and converts it to args
* Takes a passed params and converts it to args
*
* @param array $params
* @return array Array containing passed and named parameters
@ -1263,5 +1267,6 @@ class Router {
return compact('pass', 'named');
}
}
//Save the initial state
Router::reload();

View file

@ -106,6 +106,9 @@ class DatabaseSession implements CakeSessionHandlerInterface {
* @access private
*/
public function write($id, $data) {
if (!$id) {
return false;
}
$expires = time() + (Configure::read('Session.timeout') * 60);
return ClassRegistry::getObject('Session')->save(compact('id', 'data', 'expires'));
}

View file

@ -1001,7 +1001,10 @@ class FormHelper extends AppHelper {
if (empty($options['value'])) {
$options['value'] = 1;
} elseif (!empty($value) && $value === $options['value']) {
} elseif (
(!isset($options['checked']) && !empty($value) && $value === $options['value']) ||
!empty($options['checked'])
) {
$options['checked'] = 'checked';
}
if ($options['hiddenField']) {
@ -2021,7 +2024,7 @@ class FormHelper extends AppHelper {
return $options;
}
$name = $this->_View->field;
$name = !empty($this->_View->field) ? $this->_View->field : $this->_View->model;
if (!empty($this->_View->fieldSuffix)) {
$name .= '[' . $this->_View->fieldSuffix . ']';
}

View file

@ -180,8 +180,9 @@ class TextHelper extends AppHelper {
*/
public function autoLinkEmails($text, $options = array()) {
$this->_linkOptions = $options;
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
return preg_replace_callback(
'#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i',
array(&$this, '_linkEmails'),
$text
);

View file

@ -326,6 +326,7 @@ class View extends Object {
return $contents;
}
}
$file = $this->_getElementFilename($name, $plugin);
if ($file) {
@ -698,10 +699,7 @@ class View extends Object {
}
$paths = $this->_paths($this->plugin);
$exts = array($this->ext);
if ($this->ext !== '.ctp') {
array_push($exts, '.ctp');
}
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . $name . $ext)) {
@ -742,10 +740,7 @@ class View extends Object {
$paths = $this->_paths($this->plugin);
$file = 'layouts' . DS . $subDir . $name;
$exts = array($this->ext);
if ($this->ext !== '.ctp') {
array_push($exts, '.ctp');
}
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . $file . $ext)) {
@ -756,6 +751,21 @@ class View extends Object {
throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext));
}
/**
* Get the extensions that view files can use.
*
* @return array Array of extensions view files use.
* @access protected
*/
function _getExtensions() {
$exts = array($this->ext);
if ($this->ext !== '.ctp') {
array_push($exts, '.ctp');
}
return $exts;
}
/**
* Finds an element filename, returns false on failure.
*
@ -765,11 +775,14 @@ class View extends Object {
*/
protected function _getElementFileName($name, $plugin = null) {
$paths = $this->_paths($plugin);
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
return $path . 'elements' . DS . $name . $this->ext;
}
}
}
return false;
}

View file

@ -90,7 +90,13 @@ class BasicsTest extends CakeTestCase {
$__ENV = $_ENV;
$_SERVER['HTTP_HOST'] = 'localhost';
$this->assertEqual(env('HTTP_BASE'), '');
$this->assertEqual(env('HTTP_BASE'), '.localhost');
$_SERVER['HTTP_HOST'] = 'com.ar';
$this->assertEqual(env('HTTP_BASE'), '.com.ar');
$_SERVER['HTTP_HOST'] = 'example.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.ar');
$_SERVER['HTTP_HOST'] = 'example.com';
$this->assertEqual(env('HTTP_BASE'), '.example.com');
@ -101,9 +107,21 @@ class BasicsTest extends CakeTestCase {
$_SERVER['HTTP_HOST'] = 'subdomain.example.com';
$this->assertEqual(env('HTTP_BASE'), '.example.com');
$_SERVER['HTTP_HOST'] = 'example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'www.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
$_SERVER = $_ENV = array();
$_SERVER['SCRIPT_NAME'] = '/a/test/test.php';

View file

@ -31,7 +31,13 @@ class TestMemcacheEngine extends MemcacheEngine {
function parseServerString($server) {
return $this->_parseServerString($server);
}
function setMemcache(&$memcache) {
$this->__Memcache = $memcache;
}
}
Mock::generate('Memcache', 'MemcacheMockMemcache');
/**
* MemcacheEngineTest class
@ -357,7 +363,23 @@ class MemcacheEngineTest extends CakeTestCase {
$this->assertTrue($result, 'Could not write with duration 0');
$result = Cache::read('test_key', 'memcache');
$this->assertEqual($result, 'written!');
}
/**
* test that durations greater than 30 days never expire
*
* @return void
*/
function testLongDurationEqualToZero() {
$memcache =& new TestMemcacheEngine();
$memcache->settings['compress'] = false;
$mock = new MemcacheMockMemcache();
$memcache->setMemcache($mock);
$mock->expectAt(0, 'set', array('key', 'value', false, 0));
$value = 'value';
$memcache->write('key', $value, 50 * DAY);
}
}

View file

@ -702,4 +702,35 @@ class CakeSessionTest extends CakeTestCase {
$this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']);
}
/**
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function testDatabaseStorageEmptySessionId() {
unset($_SESSION);
session_destroy();
Configure::write('Session.table', 'sessions');
Configure::write('Session.model', 'Session');
Configure::write('Session.database', 'test_suite');
Configure::write('Session.save', 'database');
$this->setUp();
$id = $this->Session->id();
$this->Session->id = '';
session_id('');
$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
session_write_close();
unset($_SESSION);
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'php');
session_id($id);
$this->setUp();
}
}

View file

@ -1505,7 +1505,6 @@ class ModelWriteTest extends BaseModelTest {
);
$TestModel->save($data);
$result = $TestModel->read(null, 1);
$time = date('Y-M-D H:i:s');
$expected = array(4, 5);
$this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/id', $result), $expected);
$expected = array('new record', 'new record');

View file

@ -2168,6 +2168,35 @@ class FormHelperTest extends CakeTestCase {
'/div'
);
$this->assertTags($result, $expected);
$this->Form->data = array();
$result = $this->Form->input('Publisher.id', array(
'label' => 'Publisher',
'type' => 'select',
'multiple' => 'checkbox',
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'PublisherId')),
'Publisher',
'/label',
'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
array('label' => array('for' => 'PublisherIdValue1')),
'Label 1',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
array('label' => array('for' => 'PublisherIdValue2')),
'Label 2',
'/label',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
@ -3762,27 +3791,6 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => true));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->request->data['Contact']['published'] = 1;
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
@ -3823,6 +3831,49 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* test the checked option for checkboxes.
*
* @return void
*/
function testCheckboxCheckedOption() {
$result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => true));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = 1;
$result = $this->Form->checkbox('Model.field', array('checked' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
);
$this->assertTags($result, $expected);
}
/**
* Test that disabling a checkbox also disables the hidden input so no value is submitted
*
@ -5751,6 +5802,28 @@ class FormHelperTest extends CakeTestCase {
)));
}
/**
* test get form, and inputs when the model param is false
*
* @return void
*/
function testGetFormWithFalseModel() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create(false, array('type' => 'get'));
$expected = array('form' => array(
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->text('reason');
$expected = array(
'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
);
$this->assertTags($result, $expected);
}
/**
* test that datetime() works with GET style forms.
*

View file

@ -273,6 +273,16 @@ class TextHelperTest extends CakeTestCase {
$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a url http://www.does--not--work.com and more';
$expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a url http://www.not--work.com and more';
$expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
}
/**
@ -292,6 +302,11 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLinkEmails($text);
$this->assertPattern('#^' . $expected . '$#', $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEqual($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));

View file

@ -544,6 +544,21 @@ class ViewTest extends CakeTestCase {
$this->assertInstanceOf('HtmlHelper', $View->Html);
}
/**
* test that ctp is used as a fallback file extension for elements
*
* @return void
*/
function testElementCtpFallback() {
$View = new TestView($this->PostsController);
$View->ext = '.missing';
$element = 'test_element';
$expected = 'this is the test element';
$result = $View->element($element);
$this->assertEqual($expected, $result);
}
/**
* testLoadHelpers method
*