diff --git a/cake/basics.php b/cake/basics.php index 5a968cdeb..58ee67c41 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -282,7 +282,7 @@ if (!function_exists('sortByKey')) { if (defined('SERVER_IIS') && SERVER_IIS === true) { return str_replace('\\\\', '\\', env('PATH_TRANSLATED')); } - break; + break; case 'DOCUMENT_ROOT': $name = env('SCRIPT_NAME'); $filename = env('SCRIPT_FILENAME'); @@ -291,20 +291,31 @@ if (!function_exists('sortByKey')) { $offset = 4; } return substr($filename, 0, strlen($filename) - (strlen($name) + $offset)); - break; + break; case 'PHP_SELF': return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME')); - break; + break; case 'CGI_MODE': return (PHP_SAPI === 'cgi'); - break; + 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; + } } - return '.' . $host; - break; + array_shift($parts); + return '.' . implode('.', $parts); + break; } return null; } diff --git a/cake/console/libs/task_collection.php b/cake/console/libs/task_collection.php index 32f0b31a4..df29d3d26 100644 --- a/cake/console/libs/task_collection.php +++ b/cake/console/libs/task_collection.php @@ -48,11 +48,10 @@ class TaskCollection extends ObjectCollection { * * @param string $task Task name to load * @param array $settings Settings for the task. - * @param boolean $enable Whether or not this task should be enabled by default * @return Task A task object, Either the existing loaded task or a new one. * @throws MissingTaskFileException, MissingTaskClassException when the task could not be found */ - public function load($task, $settings = array(), $enable = true) { + public function load($task, $settings = array()) { list($plugin, $name) = pluginSplit($task, true); if (isset($this->_loaded[$name])) { @@ -72,6 +71,7 @@ class TaskCollection extends ObjectCollection { $this->_loaded[$name] = new $taskClass( $this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin ); + $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { $this->_enabled[] = $name; } diff --git a/cake/console/templates/default/classes/fixture.ctp b/cake/console/templates/default/classes/fixture.ctp index dd1b5b478..bbb727dd6 100644 --- a/cake/console/templates/default/classes/fixture.ctp +++ b/cake/console/templates/default/classes/fixture.ctp @@ -20,7 +20,7 @@ */ ?> -/* Fixture generated on: */ +/* Fixture generated on: */ class Fixture extends CakeTestFixture { public $name = ''; diff --git a/cake/console/templates/default/classes/test.ctp b/cake/console/templates/default/classes/test.ctp index f9dd98b0b..6e8c1ba76 100644 --- a/cake/console/templates/default/classes/test.ctp +++ b/cake/console/templates/default/classes/test.ctp @@ -18,7 +18,7 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ echo " App::import('', ''); diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 79d98376e..012eceba0 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine { * @var Memcache * @access private */ - private $__Memcache = null; + protected $_Memcache = null; /** * Settings @@ -74,12 +74,12 @@ class MemcacheEngine extends CacheEngine { if (!is_array($this->settings['servers'])) { $this->settings['servers'] = array($this->settings['servers']); } - if (!isset($this->__Memcache)) { + if (!isset($this->_Memcache)) { $return = false; - $this->__Memcache = new Memcache(); + $this->_Memcache = new Memcache(); foreach ($this->settings['servers'] as $server) { list($host, $port) = $this->_parseServerString($server); - if ($this->__Memcache->addServer($host, $port)) { + if ($this->_Memcache->addServer($host, $port)) { $return = true; } } @@ -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,7 +125,10 @@ class MemcacheEngine extends CacheEngine { * @see http://php.net/manual/en/memcache.set.php */ public function write($key, $value, $duration) { - return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration); + if ($duration > 30 * DAY) { + $duration = 0; + } + return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration); } /** @@ -136,7 +138,7 @@ class MemcacheEngine extends CacheEngine { * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it */ public function read($key) { - return $this->__Memcache->get($key); + return $this->_Memcache->get($key); } /** @@ -154,7 +156,7 @@ class MemcacheEngine extends CacheEngine { __('Method increment() not implemented for compressed cache in %s', __CLASS__) ); } - return $this->__Memcache->increment($key, $offset); + return $this->_Memcache->increment($key, $offset); } /** @@ -172,7 +174,7 @@ class MemcacheEngine extends CacheEngine { __('Method decrement() not implemented for compressed cache in %s', __CLASS__) ); } - return $this->__Memcache->decrement($key, $offset); + return $this->_Memcache->decrement($key, $offset); } /** @@ -182,7 +184,7 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed */ public function delete($key) { - return $this->__Memcache->delete($key); + return $this->_Memcache->delete($key); } /** @@ -191,7 +193,7 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if the cache was succesfully cleared, false otherwise */ public function clear($check) { - return $this->__Memcache->flush(); + return $this->_Memcache->flush(); } /** @@ -202,8 +204,8 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if memcache server was connected */ public function connect($host, $port = 11211) { - if ($this->__Memcache->getServerStatus($host, $port) === 0) { - if ($this->__Memcache->connect($host, $port)) { + if ($this->_Memcache->getServerStatus($host, $port) === 0) { + if ($this->_Memcache->connect($host, $port)) { return true; } return false; diff --git a/cake/libs/controller/component_collection.php b/cake/libs/controller/component_collection.php index 5efb7c888..2a483cc21 100644 --- a/cake/libs/controller/component_collection.php +++ b/cake/libs/controller/component_collection.php @@ -74,7 +74,7 @@ class ComponentCollection extends ObjectCollection { * @throws MissingComponentFileException, MissingComponentClassException when the component could not be found */ public function load($component, $settings = array()) { - if (isset($settings['className'])) { + if (is_array($settings) && isset($settings['className'])) { $alias = $component; $component = $settings['className']; } diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 3889f716c..f818ef63b 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -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) { - $this->response->type($cType); + if (empty($this->request->params['requested'])) { + $this->response->type($cType); + } if (!empty($options['charset'])) { $this->response->charset($options['charset']); diff --git a/cake/libs/model/behavior_collection.php b/cake/libs/model/behavior_collection.php index 2035a77a0..30c9c1469 100644 --- a/cake/libs/model/behavior_collection.php +++ b/cake/libs/model/behavior_collection.php @@ -99,7 +99,7 @@ class BehaviorCollection extends ObjectCollection { * @throws MissingBehaviorFileException or MissingBehaviorClassException when a behavior could not be found. */ public function load($behavior, $config = array()) { - if (isset($config['className'])) { + if (is_array($config) && isset($config['className'])) { $alias = $behavior; $behavior = $config['className']; } diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index a38e0ed7b..fb3a77c13 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -365,7 +365,7 @@ class CakeSchema extends Object { $out .= "}\n"; $file = new SplFileObject($path . DS . $file, 'w+'); - $content = ""; + $content = ""; if ($file->fwrite($content)) { return $content; } diff --git a/cake/libs/model/db_acl.php b/cake/libs/model/db_acl.php index e8a31cef7..4782cfc91 100644 --- a/cake/libs/model/db_acl.php +++ b/cake/libs/model/db_acl.php @@ -46,7 +46,7 @@ class AclNode extends AppModel { * @var array * @access public */ - public $actsAs = array('Tree' => 'nested'); + public $actsAs = array('Tree' => array('nested')); /** * Constructor diff --git a/cake/libs/route/cake_route.php b/cake/libs/route/cake_route.php index be944951f..798d26c92 100644 --- a/cake/libs/route/cake_route.php +++ b/cake/libs/route/cake_route.php @@ -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. diff --git a/cake/libs/router.php b/cake/libs/router.php index c0737ae25..16af52f67 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -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(); diff --git a/cake/libs/session/database_session.php b/cake/libs/session/database_session.php index 574d1f5c0..ceff5fdb0 100644 --- a/cake/libs/session/database_session.php +++ b/cake/libs/session/database_session.php @@ -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')); } diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 35e6e0dd4..d90289e21 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -57,7 +57,7 @@ class HelperCollection extends ObjectCollection { * @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found */ public function load($helper, $settings = array()) { - if (isset($settings['className'])) { + if (is_array($settings) && isset($settings['className'])) { $alias = $helper; $helper = $settings['className']; } diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index dd1c7d85f..f397c670d 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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']) { @@ -1322,7 +1325,6 @@ class FormHelper extends AppHelper { unset($options['confirm']); } - $url = $this->url($url); $formName = uniqid('post_'); $out = $this->create(false, array('url' => $url, 'name' => $formName, 'id' => $formName, 'style' => 'display:none;')); if (isset($options['data']) && is_array($options['data'])) { @@ -2021,7 +2023,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 . ']'; } diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 12eff3893..307859513 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -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 ); diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index ef1d46b9f..7ff7ed9fa 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -326,6 +326,7 @@ class View extends Object { return $contents; } } + $file = $this->_getElementFilename($name, $plugin); if ($file) { @@ -623,7 +624,7 @@ class View extends Object { public function loadHelpers() { $helpers = HelperCollection::normalizeObjectArray($this->helpers); foreach ($helpers as $name => $properties) { - $this->Helpers->load($properties['class'], $properties['settings'], true); + $this->Helpers->load($properties['class'], $properties['settings']); } $this->_helpersLoaded = true; } @@ -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)) { @@ -741,11 +739,8 @@ 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,9 +775,12 @@ class View extends Object { */ protected function _getElementFileName($name, $plugin = null) { $paths = $this->_paths($plugin); - foreach ($paths as $path) { - if (file_exists($path . 'elements' . DS . $name . $this->ext)) { - return $path . 'elements' . DS . $name . $this->ext; + $exts = $this->_getExtensions(); + foreach ($exts as $ext) { + foreach ($paths as $path) { + if (file_exists($path . 'elements' . DS . $name . $ext)) { + return $path . 'elements' . DS . $name . $ext; + } } } return false; diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index c5f4c3ca3..e3090938a 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -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'; diff --git a/cake/tests/cases/console/libs/task_collection.test.php b/cake/tests/cases/console/libs/task_collection.test.php index 27a43e619..74c0c61f2 100644 --- a/cake/tests/cases/console/libs/task_collection.test.php +++ b/cake/tests/cases/console/libs/task_collection.test.php @@ -63,7 +63,7 @@ class TaskCollectionTest extends CakeTestCase { * @return void */ function testLoadWithEnableFalse() { - $result = $this->Tasks->load('DbConfig', array(), false); + $result = $this->Tasks->load('DbConfig', array('enabled' => false)); $this->assertInstanceOf('DbConfigTask', $result); $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 42324a8bc..61bcec550 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -31,6 +31,10 @@ class TestMemcacheEngine extends MemcacheEngine { function parseServerString($server) { return $this->_parseServerString($server); } + + function setMemcache($memcache) { + $this->_Memcache = $memcache; + } } /** @@ -357,7 +361,25 @@ 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 = $this->getMock('Memcache'); + $memcache->setMemcache($mock); + $mock->expects($this->once()) + ->method('set') + ->with('key', 'value', false, 0); + + $value = 'value'; + $memcache->write('key', $value, 50 * DAY); } } diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 44a6585c6..27e5fde37 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -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'); diff --git a/cake/tests/cases/libs/object_collection.test.php b/cake/tests/cases/libs/object_collection.test.php index b01a93627..e3a0f82ca 100644 --- a/cake/tests/cases/libs/object_collection.test.php +++ b/cake/tests/cases/libs/object_collection.test.php @@ -54,16 +54,16 @@ class GenericObjectCollection extends ObjectCollection { * * @param string $object Object name * @param array $settings Settings array - * @param boolean $enable Start object as enabled * @return array List of loaded objects */ - public function load($object, $settings = array(), $enable = true) { + public function load($object, $settings = array()) { list($plugin, $name) = pluginSplit($object); if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } $objectClass = $name . 'GenericObject'; $this->_loaded[$name] = new $objectClass($this, $settings); + $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { $this->_enabled[] = $name; } diff --git a/cake/tests/cases/libs/session/database_session.test.php b/cake/tests/cases/libs/session/database_session.test.php index b3c457c2d..657ce8159 100644 --- a/cake/tests/cases/libs/session/database_session.test.php +++ b/cake/tests/cases/libs/session/database_session.test.php @@ -126,6 +126,16 @@ class DatabaseSessionTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * testReadAndWriteWithDatabaseStorage method + * + * @access public + * @return void + */ + function testWriteEmptySessionId() { + $result = $this->storage->write('', 'This is a Test'); + $this->assertFalse($result); + } /** * test read() * diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 6a4f29403..c4f1e9dd7 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -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); } /** @@ -3123,7 +3152,7 @@ class FormHelperTest extends CakeTestCase { '/select' ); $this->assertTags($result, $expected); - + $options = array( '>< Key' => array( 1 => 'One', @@ -3500,7 +3529,7 @@ class FormHelperTest extends CakeTestCase { */ function testSelectMultipleCheckboxDiv() { $result = $this->Form->select( - 'Model.tags', + 'Model.tags', array('first', 'second'), array('multiple' => 'checkbox', 'class' => 'my-class') ); @@ -3528,7 +3557,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->input('Model.tags', array( 'options' => array('first', 'second'), - 'multiple' => 'checkbox', + 'multiple' => 'checkbox', 'class' => 'my-class', 'div' => false, 'label' => false @@ -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. * diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 03ad9ee2f..f02549044 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -273,6 +273,16 @@ class TextHelperTest extends CakeTestCase { $expected = 'Text with a url www.cot.ag/cuIb2Q 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 http://www.does--not--work.com 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 http://www.not--work.com and more'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEqual($expected, $result); } /** @@ -291,6 +301,11 @@ class TextHelperTest extends CakeTestCase { $expected = 'Text with email@example.com address'; $result = $this->Text->autoLinkEmails($text); $this->assertPattern('#^' . $expected . '$#', $result); + + $text = "Text with o'hare._-bob@example.com address"; + $expected = 'Text with o'hare._-bob@example.com address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEqual($expected, $result); $text = 'Text with email@example.com address'; $expected = 'Text with email@example.com address'; diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 70ef8a6ca..2b6417e5a 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -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 *