Permalink
Browse files

Merge branch '2.0' of github.com:cakephp/cakephp into 2.0

  • Loading branch information...
lorenzo committed Aug 29, 2011
2 parents 40ba400 + 59c6b41 commit 0e85170f28d00a8157d750bfe1148ffd462f73b1
@@ -240,7 +240,9 @@ public function clear($check) {
}
$path = $this->_File->getRealPath();
$this->_File = null;
- unlink($path);
+ if (file_exists($path)) {
+ unlink($path);
+ }
}
$dir->close();
return true;
@@ -65,6 +65,8 @@ public function startup() {
* @return mixed
*/
public function main() {
+ Configure::write('Cache.disable', 1);
+
if (!is_dir($this->DbConfig->path)) {
$path = $this->Project->execute();
if (!empty($path)) {
@@ -43,6 +43,17 @@ class BakeTask extends Shell {
*/
public $interactive = false;
+/**
+ * Disable caching for baking.
+ * This forces the most current database schema to be used.
+ *
+ * @return void
+ */
+ function startup() {
+ Configure::write('Cache.disable', 1);
+ parent::startup();
+ }
+
/**
* Gets the path for output. Checks the plugin property
* and returns the correct path.
@@ -316,35 +316,30 @@ protected function _generateRecords($tableInfo, $recordCount = 1) {
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
}
}
- $insert = "'$insert'";
break;
case 'timestamp':
- $ts = time();
- $insert = "'$ts'";
+ $insert = time();
break;
case 'datetime':
- $ts = date('Y-m-d H:i:s');
- $insert = "'$ts'";
+ $insert = date('Y-m-d H:i:s');
break;
case 'date':
- $ts = date('Y-m-d');
- $insert = "'$ts'";
+ $insert = date('Y-m-d');
break;
case 'time':
- $ts = date('H:i:s');
- $insert = "'$ts'";
+ $insert = date('H:i:s');
break;
case 'boolean':
$insert = 1;
break;
case 'text':
- $insert = "'Lorem ipsum dolor sit amet, aliquet feugiat.";
+ $insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
$insert .= " Convallis morbi fringilla gravida,";
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
- $insert .= " duis vestibulum nunc mattis convallis.'";
+ $insert .= " duis vestibulum nunc mattis convallis.";
break;
}
$record[$field] = $insert;
@@ -365,7 +360,8 @@ protected function _makeRecordString($records) {
foreach ($records as $record) {
$values = array();
foreach ($record as $field => $value) {
- $values[] = "\t\t\t'$field' => $value";
+ $val = var_export($value, true);
+ $values[] = "\t\t\t'$field' => $val";
}
$out .= "\t\tarray(\n";
$out .= implode(",\n", $values);
@@ -408,7 +404,7 @@ protected function _getRecordsFromTable($modelName, $useTable = null) {
foreach ($records as $record) {
$row = array();
foreach ($record[$modelObject->alias] as $field => $value) {
- $row[$field] = $db->value($value, $schema[$field]['type']);
+ $row[$field] = $value;
}
$out[] = $row;
}
View
@@ -427,6 +427,9 @@ public static function core($type) {
*
* `App::objects('MyPlugin.Model');` returns `array('MyPluginPost', 'MyPluginComment');`
*
+ * When scanning directories, files and directories beginning with `.` will be excluded as these
+ * are commonly used by version control systems.
+ *
* @param string $type Type of object, i.e. 'Model', 'Controller', 'View/Helper', 'file', 'class' or 'plugin'
* @param mixed $path Optional Scan only the path given. If null, paths for the chosen type will be used.
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
@@ -476,12 +479,13 @@ public static function objects($type, $path = null, $cache = true) {
if ($dir != APP && is_dir($dir)) {
$files = new RegexIterator(new DirectoryIterator($dir), $extension);
foreach ($files as $file) {
- if (!$file->isDot()) {
+ $fileName = basename($file);
+ if (!$file->isDot() && $fileName[0] !== '.') {
$isDir = $file->isDir() ;
if ($isDir && $includeDirectories) {
- $objects[] = basename($file);
+ $objects[] = $fileName;
} elseif (!$includeDirectories && !$isDir) {
- $objects[] = substr(basename($file), 0, -4);
+ $objects[] = substr($fileName, 0, -4);
}
}
}
View
@@ -93,6 +93,7 @@ class L10n {
/* Arabic */ 'ara' => 'ar',
/* Armenian - Armenia */ 'hye' => 'hy',
/* Basque */ 'baq' => 'eu',
+ /* Tibetan */ 'bod' => 'bo',
/* Bosnian */ 'bos' => 'bs',
/* Bulgarian */ 'bul' => 'bg',
/* Byelorussian */ 'bel' => 'be',
@@ -194,6 +195,9 @@ class L10n {
'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8', 'direction' => 'ltr'),
'bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8', 'direction' => 'ltr'),
+ 'bo' => array('language' => 'Tibetan', 'locale' => 'bod', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
+ 'bo-cn' => array('language' => 'Tibetan (China)', 'locale' => 'bo_cn', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
+ 'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'),
'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr'),
@@ -605,23 +605,35 @@ public function subdomains($tldLength = 1) {
*
* `$this->request->accepts('json');`
*
+ * This method will order the returned content types by the preference values indicated
+ * by the client.
+ *
* @param string $type The content type to check for. Leave null to get all types a client accepts.
* @return mixed Either an array of all the types the client accepts or a boolean if they accept the
* provided type.
*/
public function accepts($type = null) {
- $acceptTypes = explode(',', $this->header('accept'));
- $acceptTypes = array_map('trim', $acceptTypes);
- foreach ($acceptTypes as $i => $accepted) {
- if (strpos($accepted, ';') !== false) {
- list($accepted) = explode(';', $accepted);
- $acceptTypes[$i] = $accepted;
+ $accept = array();
+ $header = explode(',', $this->header('accept'));
+ foreach (array_filter(array_reverse($header)) as $value) {
+ $prefPos = strpos($value, ';');
+ if ($prefPos !== false) {
+ $prefValue = (float) substr($value, strpos($value, '=') + 1);
+ $value = trim(substr($value, 0, $prefPos));
+ } else {
+ $prefValue = 1.0;
+ $value = trim($value);
+ }
+ if ($prefValue) {
+ $accept[$value] = $prefValue;
}
}
+ arsort($accept);
+ $accept = array_keys($accept);
if ($type === null) {
- return $acceptTypes;
+ return $accept;
}
- return in_array($type, $acceptTypes);
+ return in_array($type, $accept);
}
/**
@@ -36,8 +36,7 @@ public static function suite() {
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentCollectionTest.php');
- $suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
- $suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component' . DS . 'Auth');
+ $suite->addTestDirectoryRecursive(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
return $suite;
}
}
@@ -164,6 +164,31 @@ public function testImportOptionsAlternateConnection() {
$this->assertPattern("/'connection' => 'test'/", $result);
}
+/**
+ * Ensure that fixture data doesn't get overly escaped.
+ *
+ * @return void
+ */
+ function testImportRecordsNoEscaping() {
+ $Article = ClassRegistry::init('Article');
+ $Article->updateAll(array('body' => "'Body \"value\"'"));
+
+ $this->Task->interactive = true;
+ $this->Task->expects($this->at(0))
+ ->method('in')
+ ->will($this->returnValue('WHERE 1=1 LIMIT 10'));
+
+ $this->Task->connection = 'test';
+ $this->Task->path = '/my/path/';
+ $result = $this->Task->bake('Article', false, array(
+ 'fromTable' => true,
+ 'schema' => 'Article',
+ 'records' => false
+ ));
+
+ $this->assertRegExp("/'body' => 'Body \"value\"'/", $result, 'Data has bad escaping');
+ }
+
/**
* test that execute passes runs bake depending with named model.
*
@@ -157,7 +157,7 @@ public function testConstructorSettings() {
*/
public function testInitializeCallback() {
$this->assertNull($this->RequestHandler->ext);
- $this->Controller->request->params['url']['ext'] = 'rss';
+ $this->Controller->request->params['ext'] = 'rss';
$this->RequestHandler->initialize($this->Controller);
$this->assertEqual($this->RequestHandler->ext, 'rss');
}
@@ -222,7 +222,7 @@ public function testDisabling() {
*/
public function testAutoResponseType() {
$this->Controller->ext = '.thtml';
- $this->Controller->request->params['url']['ext'] = 'rss';
+ $this->Controller->request->params['ext'] = 'rss';
$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->Controller->ext, '.ctp');
@@ -240,7 +240,7 @@ public function testAutoAjaxLayout() {
$this->assertEquals($this->Controller->layout, $this->RequestHandler->ajaxLayout);
$this->_init();
- $this->Controller->request->params['url']['ext'] = 'js';
+ $this->Controller->request->params['ext'] = 'js';
$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertNotEqual($this->Controller->layout, 'ajax');
@@ -305,6 +305,21 @@ public function testListObjects() {
App::build();
}
+/**
+ * Make sure that .svn and friends are excluded from App::objects('plugin')
+ */
+ public function testListObjectsIgnoreDotDirectories() {
+ $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
+ App::build(array(
+ 'plugins' => array($path)
+ ), true);
+ mkdir($path . '.svn');
+ $result = App::objects('plugin', null, false);
+ rmdir($path . '.svn');
+
+ $this->assertNotContains('.svn', $result);
+ }
+
/**
* Tests listing objects within a plugin
*
@@ -785,7 +785,7 @@ public function testAccepts() {
$result = $request->accepts();
$expected = array(
- 'text/xml', 'application/xml', 'application/xhtml+xml', 'text/html', 'text/plain', 'image/png'
+ 'text/xml', 'application/xhtml+xml', 'text/html', 'image/png', 'text/plain', 'application/xml'
);
$this->assertEquals($expected, $result, 'Content types differ.');
@@ -813,6 +813,19 @@ public function testAcceptWithWhitespace() {
$this->assertTrue($request->accepts('text/html'));
}
+/**
+ * Content types from accepts() should respect the client's q preference values.
+ *
+ * @return void
+ */
+ public function testAcceptWithQvalueSorting() {
+ $_SERVER['HTTP_ACCEPT'] = 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0';
+ $request = new CakeRequest('/', false);
+ $result = $request->accepts();
+ $expected = array('application/xml', 'text/html', 'application/json');
+ $this->assertEquals($expected, $result);
+ }
+
/**
* testBaseUrlAndWebrootWithModRewrite method
*
@@ -106,6 +106,8 @@ public function testInflectingSingulars() {
$this->assertEqual(Inflector::singularize('bases'), 'basis');
$this->assertEqual(Inflector::singularize('analyses'), 'analysis');
$this->assertEqual(Inflector::singularize('curves'), 'curve');
+ $this->assertEqual(Inflector::singularize('cafes'), 'cafe');
+ $this->assertEqual(Inflector::singularize('roofs'), 'roof');
$this->assertEqual(Inflector::singularize(''), '');
}
@@ -153,6 +155,8 @@ public function testInflectingPlurals() {
$this->assertEqual(Inflector::pluralize('tax'), 'taxes');
$this->assertEqual(Inflector::pluralize('wave'), 'waves');
$this->assertEqual(Inflector::pluralize('bureau'), 'bureaus');
+ $this->assertEqual(Inflector::pluralize('cafe'), 'cafes');
+ $this->assertEqual(Inflector::pluralize('roof'), 'roofs');
$this->assertEqual(Inflector::pluralize(''), '');
}
@@ -1366,6 +1366,7 @@ public function testDateMmmmDdyyyy() {
$this->assertTrue(Validation::date('Dec 27 2006', array('Mdy')));
$this->assertFalse(Validation::date('27 Dec 2006', array('Mdy')));
$this->assertFalse(Validation::date('2006 December 27', array('Mdy')));
+ $this->assertTrue(Validation::date('Sep 12, 2011', array('Mdy')));
}
/**
@@ -18,6 +18,8 @@
*/
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
+App::uses('Folder', 'Utility');
+
class CakeTestSuite extends PHPUnit_Framework_TestSuite {
/**
@@ -27,13 +29,10 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
* @return void
*/
public function addTestDirectory($directory = '.') {
- $files = new DirectoryIterator($directory);
+ $folder = new Folder($directory);
+ list($dirs, $files) = $folder->read(true, false, true);
foreach ($files as $file) {
- if (!$file->isFile()) {
- continue;
- }
- $file = $file->getRealPath();
$this->addTestFile($file);
}
}
@@ -45,15 +44,12 @@ public function addTestDirectory($directory = '.') {
* @return void
*/
public function addTestDirectoryRecursive($directory = '.') {
- $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
+ $folder = new Folder($directory);
+ $files = $folder->tree(null, false, 'files');
foreach ($files as $file) {
- if (!$file->isFile()) {
- continue;
- }
- $file = $file->getRealPath();
$this->addTestFile($file);
}
}
-}
+}
Oops, something went wrong.

0 comments on commit 0e85170

Please sign in to comment.