Browse Source

Merge branch '2.0' into 2.1

mark_story 14 years ago
parent
commit
07a2a60468

+ 1 - 1
app/View/Pages/home.ctp

@@ -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>

+ 2 - 2
lib/Cake/Console/Command/Task/FixtureTask.php

@@ -222,14 +222,14 @@ class FixtureTask extends BakeTask {
 			$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'));

+ 1 - 1
lib/Cake/Console/Shell.php

@@ -657,7 +657,7 @@ class Shell extends Object {
 		}
 
 		$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));

+ 4 - 4
lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php

@@ -361,7 +361,7 @@ class FileEngineTest extends CakeTestCase {
 		$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');
 
@@ -369,7 +369,7 @@ class FileEngineTest extends CakeTestCase {
 		$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');
 
@@ -377,7 +377,7 @@ class FileEngineTest extends CakeTestCase {
 		$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');
 
@@ -385,7 +385,7 @@ class FileEngineTest extends CakeTestCase {
 		$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');
 	}

+ 23 - 8
lib/Cake/Test/Case/Console/ShellTest.php

@@ -126,6 +126,11 @@ class ShellTest extends CakeTestCase {
 		$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 @@ class ShellTest extends CakeTestCase {
 		$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 @@ class ShellTest extends CakeTestCase {
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
 		$this->assertEquals(file_get_contents($file), $contents);
-
-		$Folder->delete();
 	}
 
 /**
@@ -588,8 +586,25 @@ class ShellTest extends CakeTestCase {
 		$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);
 	}
 
 /**

+ 1 - 1
lib/Cake/Test/Case/Model/BehaviorCollectionTest.php

@@ -890,7 +890,7 @@ class BehaviorCollectionTest extends CakeTestCase {
 		$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')));

+ 61 - 3
lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php

@@ -1943,7 +1943,7 @@ class MysqlTest extends CakeTestCase {
 		$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 @@ class MysqlTest extends CakeTestCase {
 
 		$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 @@ class MysqlTest extends CakeTestCase {
 		$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 @@ class MysqlTest extends CakeTestCase {
 			'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');
+	}
 }

+ 0 - 39
lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

@@ -740,45 +740,6 @@ class DboSourceTest extends CakeTestCase {
 		$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

+ 1 - 1
lib/Cake/Test/Case/Model/ModelIntegrationTest.php

@@ -272,7 +272,7 @@ class ModelIntegrationTest extends BaseModelTest {
 			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);
 	}
 
 /**

+ 5 - 5
lib/Cake/Test/Case/Model/ModelReadTest.php

@@ -7561,7 +7561,7 @@ class ModelReadTest extends BaseModelTest {
 			'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(
@@ -7569,23 +7569,23 @@ class ModelReadTest extends BaseModelTest {
 			'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);
 	}
 
 /**

+ 3 - 3
lib/Cake/Test/Case/Routing/RouterTest.php

@@ -149,7 +149,7 @@ class RouterTest extends CakeTestCase {
 			'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 @@ class RouterTest extends CakeTestCase {
 			'id' => '13',
 			'[method]' => 'GET'
 		);
-		$this->assertEquals($result, $expected);
+		$this->assertEquals($expected, $result);
 	}
 
 /**
@@ -189,7 +189,7 @@ class RouterTest extends CakeTestCase {
 			'action' => 'index',
 			'[method]' => 'GET'
 		);
-		$this->assertEquals($result, $expected);
+		$this->assertEquals($expected, $result);
 		$this->assertEquals($resources, array('test_plugin'));
 	}
 

+ 10 - 0
lib/Cake/Test/Case/Utility/ValidationTest.php

@@ -1412,6 +1412,16 @@ class ValidationTest extends CakeTestCase {
 	}
 
 /**
+ * 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
  *
  * @return void

+ 1 - 1
lib/Cake/TestSuite/ControllerTestCase.php

@@ -251,7 +251,7 @@ abstract class ControllerTestCase extends CakeTestCase {
 
 		$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') {

+ 1 - 3
lib/Cake/Utility/Validation.php

@@ -306,9 +306,7 @@ class Validation {
 
 		$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;
 			}
 		}