Permalink
Browse files

Merge branch '2.0' into 2.1

  • Loading branch information...
markstory committed Dec 14, 2011
2 parents 6505dd8 + b61e3e0 commit 07a2a60468a67809b74eef79117633328e393e4d
View
@@ -171,7 +171,7 @@ You can also add some CSS styles for your pages at: APP/webroot/css.');
<ul><li><?php echo __d('cake_dev', 'The Rapid Development Framework'); ?></li></ul></li>
<li><a href="http://book.cakephp.org"><?php echo __d('cake_dev', 'CakePHP Documentation'); ?> </a>
<ul><li><?php echo __d('cake_dev', 'Your Rapid Development Cookbook'); ?></li></ul></li>
- <li><a href="http://api.cakephp.org"><?php echo __d('cake_dev', 'CakePHP API'); ?> </a>
+ <li><a href="http://api20.cakephp.org"><?php echo __d('cake_dev', 'CakePHP API'); ?> </a>
<ul><li><?php echo __d('cake_dev', 'Quick Reference'); ?></li></ul></li>
<li><a href="http://bakery.cakephp.org"><?php echo __d('cake_dev', 'The Bakery'); ?> </a>
<ul><li><?php echo __d('cake_dev', 'Everything CakePHP'); ?></li></ul></li>
@@ -222,14 +222,14 @@ public function bake($model, $useTable = false, $importOptions = array()) {
$schema = $this->_generateSchema($tableInfo);
}
- if (!isset($importOptions['records']) && !isset($importOptions['fromTable'])) {
+ if (empty($importOptions['records']) && !isset($importOptions['fromTable'])) {
$recordCount = 1;
if (isset($this->params['count'])) {
$recordCount = $this->params['count'];
}
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
}
- if (isset($this->params['records']) || isset($importOptions['fromTable'])) {
+ if (!empty($this->params['records']) || isset($importOptions['fromTable'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
@@ -657,7 +657,7 @@ public function createFile($path, $contents) {
}
$File = new File($path, true);
- if ($File->exists()) {
+ if ($File->exists() && $File->writable()) {
$data = $File->prepare($contents);
$File->write($data);
$this->out(__d('cake_console', '<success>Wrote</success> `%s`', $path));
@@ -361,31 +361,31 @@ public function testMaskSetting() {
$write = Cache::write('masking_test', $data, 'mask_test');
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS .'cake_masking_test')), -4);
$expected = '0664';
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
Cache::delete('masking_test', 'mask_test');
Cache::drop('mask_test');
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0666, 'path' => TMP . 'tests'));
$write = Cache::write('masking_test', $data, 'mask_test');
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS .'cake_masking_test')), -4);
$expected = '0666';
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
Cache::delete('masking_test', 'mask_test');
Cache::drop('mask_test');
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0644, 'path' => TMP . 'tests'));
$write = Cache::write('masking_test', $data, 'mask_test');
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS .'cake_masking_test')), -4);
$expected = '0644';
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
Cache::delete('masking_test', 'mask_test');
Cache::drop('mask_test');
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0640, 'path' => TMP . 'tests'));
$write = Cache::write('masking_test', $data, 'mask_test');
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS .'cake_masking_test')), -4);
$expected = '0640';
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
Cache::delete('masking_test', 'mask_test');
Cache::drop('mask_test');
}
@@ -126,6 +126,11 @@ public function setUp() {
$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell = new ShellTestShell($output, $error, $in);
+
+ if (is_dir(TMP . 'shell_test')) {
+ $Folder = new Folder(TMP . 'shell_test');
+ $Folder->delete();
+ }
}
/**
@@ -490,11 +495,6 @@ public function testShortPath() {
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'index.php';
$this->assertEquals($this->Shell->shortPath($path), $expected);
- // Shell::shortPath needs Folder::realpath
- // $path = DS . 'tmp' . DS . 'ab' . DS . '..' . DS . 'cd';
- // $expected = DS . 'tmp' . DS . 'cd';
- // $this->assertEquals($this->Shell->shortPath($path), $expected);
-
$path = DS . 'tmp' . DS . 'ab' . DS . DS . 'cd';
$expected = DS . 'tmp' . DS . 'ab' . DS . 'cd';
$this->assertEquals($this->Shell->shortPath($path), $expected);
@@ -542,8 +542,6 @@ public function testCreateFileNonInteractive() {
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);
-
- $Folder->delete();
}
/**
@@ -588,8 +586,25 @@ public function testCreateFileInteractive() {
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals($contents, file_get_contents($file));
+ }
- $Folder->delete();
+/**
+ * Test that you can't create files that aren't writable.
+ *
+ * @return void
+ */
+ public function testCreateFileNoPermissions() {
+ $path = TMP . 'shell_test';
+ $file = $path . DS . 'no_perms';
+
+ mkdir($path);
+ chmod($path, 0444);
+
+ $this->Shell->createFile($file, 'testing');
+ $this->assertFalse(file_exists($file));
+
+ chmod($path, 0744);
+ rmdir($path);
}
/**
@@ -890,7 +890,7 @@ public function testBehaviorSaveCallbacks() {
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
@@ -1943,7 +1943,7 @@ public function testStringConditionsParsing() {
$conditions = array('Company.name similar to ' => 'a word');
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE `Company`.`name` similar to 'a word'";
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
}
/**
@@ -2115,7 +2115,7 @@ public function testArrayConditionsParsing() {
$result = $this->Dbo->conditions(array('lower(Article.title)' => 'secrets'));
$expected = " WHERE lower(`Article`.`title`) = 'secrets'";
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$result = $this->Dbo->conditions(array('title LIKE' => '%hello'));
$expected = " WHERE `title` LIKE '%hello'";
@@ -2290,7 +2290,7 @@ public function testArrayConditionsParsing() {
$conditions = array('MysqlModel.id' => '');
$result = $this->Dbo->conditions($conditions, true, true, $this->model);
$expected = " WHERE `MysqlModel`.`id` IS NULL";
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$result = $this->Dbo->conditions(array('Listing.beds >=' => 0));
$expected = " WHERE `Listing`.`beds` >= 0";
@@ -3476,4 +3476,62 @@ public function testExceptionOnBrokenConnection() {
'database' => 'imaginary'
));
}
+
+/**
+ * testStatements method
+ *
+ * @return void
+ */
+ public function testUpdateStatements() {
+ $this->loadFixtures('Article', 'User');
+ $test = ConnectionManager::getDatasource('test');
+
+ $this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
+
+ $this->Dbo->expects($this->at(0))->method('execute')
+ ->with("UPDATE `articles` SET `field1` = 'value1' WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(1))->method('execute')
+ ->with("UPDATE `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " SET `Article`.`field1` = 2 WHERE 2=2");
+
+ $this->Dbo->expects($this->at(2))->method('execute')
+ ->with("UPDATE `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " SET `Article`.`field1` = 'value' WHERE `index` = 'val'");
+
+ $Article = new Article();
+
+ $this->Dbo->update($Article, array('field1'), array('value1'));
+ $this->Dbo->update($Article, array('field1'), array('2'), '2=2');
+ $this->Dbo->update($Article, array('field1'), array("'value'"), array('index' => 'val'));
+
+ }
+
+/**
+ * Test deletes with a mock.
+ *
+ * @return void
+ */
+ public function testDeleteStatements() {
+ $this->loadFixtures('Article', 'User');
+ $test = ConnectionManager::getDatasource('test');
+
+ $this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
+
+ $this->Dbo->expects($this->at(0))->method('execute')
+ ->with("DELETE FROM `articles` WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(1))->method('execute')
+ ->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(2))->method('execute')
+ ->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " WHERE 2=2");
+ $Article = new Article();
+
+ $this->Dbo->delete($Article);
+ $this->Dbo->delete($Article, true);
+ $this->Dbo->delete($Article, '2=2');
+ }
}
@@ -740,45 +740,6 @@ public function testFieldsUsingMethodCache() {
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
}
-/**
- * testStatements method
- *
- * @return void
- */
- public function testStatements() {
- $this->skipIf(!$this->testDb instanceof DboMysql);
-
- $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag');
- $Article = new Article();
-
- $result = $this->testDb->update($Article, array('field1'), array('value1'));
- $this->assertFalse($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result);
-
- $result = $this->testDb->update($Article, array('field1'), array('2'), '2=2');
- $this->assertFalse($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+SET\s+`Article`\.`field1`\s*=\s*2\s+WHERE\s+2\s*=\s*2\s*$/', $result);
-
- $result = $this->testDb->delete($Article);
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result);
-
- $result = $this->testDb->delete($Article, true);
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result);
-
- $result = $this->testDb->delete($Article, '2=2');
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result);
-
- $result = $this->testDb->hasAny($Article, '1=2');
- $this->assertFalse($result);
- }
/**
* Test that group works without a model
@@ -272,7 +272,7 @@ function testFindWithJoinsOption() {
array('User' => array('user' => 'mariano'), 'Article' => array('published' => 'Y')),
array('User' => array('user' => 'nate'), 'Article' => array('published' => ''))
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
}
/**
@@ -7561,31 +7561,31 @@ public function testVirtualFieldsOrder() {
'2' => 'Second Post',
'1' => 'First Post'
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC')));
$expected = array(
'1' => 'First Post',
'2' => 'Second Post',
'3' => 'Third Post'
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$Post->Author->virtualFields = array('joined' => 'Post.id * Author.id');
$result = $Post->find('all');
$result = Set::extract('{n}.Author.joined', $result);
$expected = array(1, 6, 3);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$result = $Post->find('all', array('order' => array('Author.joined' => 'ASC')));
$result = Set::extract('{n}.Author.joined', $result);
$expected = array(1, 3, 6);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$result = $Post->find('all', array('order' => array('Author.joined' => 'DESC')));
$result = Set::extract('{n}.Author.joined', $result);
$expected = array(6, 3, 1);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
}
/**
@@ -149,7 +149,7 @@ public function testPluginMapResources() {
'action' => 'index',
'[method]' => 'GET'
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$this->assertEquals($resources, array('test_plugin'));
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -163,7 +163,7 @@ public function testPluginMapResources() {
'id' => '13',
'[method]' => 'GET'
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
}
/**
@@ -189,7 +189,7 @@ public function testPluginMapResourcesWithPrefix() {
'action' => 'index',
'[method]' => 'GET'
);
- $this->assertEquals($result, $expected);
+ $this->assertEquals($expected, $result);
$this->assertEquals($resources, array('test_plugin'));
}
@@ -1411,6 +1411,16 @@ public function testDateMyNumeric() {
$this->assertFalse(Validation::date('12 06', array('my')));
}
+/**
+ * Test validating dates with multiple formats
+ *
+ * @return void
+ */
+ public function testDateMultiple() {
+ $this->assertTrue(Validation::date('2011-12-31', array('ymd', 'dmy')));
+ $this->assertTrue(Validation::date('31-12-2011', array('ymd', 'dmy')));
+ }
+
/**
* testTime method
*
@@ -251,7 +251,7 @@ protected function _testAction($url = '', $options = array()) {
$plugin = empty($request->params['plugin']) ? '' : Inflector::camelize($request->params['plugin']) . '.';
if ($this->controller === null && $this->autoMock) {
- $this->generate(Inflector::camelize($plugin . $request->params['controller']));
+ $this->generate($plugin . Inflector::camelize($request->params['controller']));
}
$params = array();
if ($options['return'] == 'result') {
@@ -306,9 +306,7 @@ public static function date($check, $format = 'ymd', $regex = null) {
$format = (is_array($format)) ? array_values($format) : array($format);
foreach ($format as $key) {
- $regex = $regex[$key];
-
- if (self::_check($check, $regex) === true) {
+ if (self::_check($check, $regex[$key]) === true) {
return true;
}
}

0 comments on commit 07a2a60

Please sign in to comment.