Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents f361c6f + 622d2f0 commit b2cbeeeb501285431bdc7fb2a5b37f260b792261 @marcopeg marcopeg committed Jan 20, 2013
@@ -105,12 +105,22 @@ public function all() {
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();
+
+ $admin = false;
+ if (!empty($this->params['admin'])) {
+ $admin = $this->Project->getPrefix();
+ }
+
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
App::uses($model, 'Model');
if (class_exists($model)) {
$actions = $this->bakeActions($controller);
+ if ($admin) {
+ $this->out(__d('cake_console', 'Adding %s methods', $admin));
+ $actions .= "\n" . $this->bakeActions($controller, $admin);
+ }
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
@@ -621,24 +621,20 @@ public function findHasOneAndMany(Model $model, $associations) {
public function findHasAndBelongsToMany(Model $model, $associations) {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) {
+ $tableName = null;
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema(true);
$offset = strpos($otherTable, $model->table . '_');
$otherOffset = strpos($otherTable, '_' . $model->table);
if ($offset === 0) {
- $offset = strlen($model->table . '_');
- $habtmName = $this->_modelName(substr($otherTable, $offset));
- $associations['hasAndBelongsToMany'][] = array(
- 'alias' => $habtmName,
- 'className' => $habtmName,
- 'foreignKey' => $foreignKey,
- 'associationForeignKey' => $this->_modelKey($habtmName),
- 'joinTable' => $otherTable
- );
+ $tableName = substr($otherTable, strlen($model->table . '_'));
} elseif ($otherOffset === 0) {
- $habtmName = $this->_modelName(substr($otherTable, 0, $otherOffset));
+ $tableName = substr($otherTable, 0, $otherOffset);
+ }
+ if ($tableName && in_array($tableName, $this->_tables)) {
+ $habtmName = $this->_modelName($tableName);
$associations['hasAndBelongsToMany'][] = array(
'alias' => $habtmName,
'className' => $habtmName,
@@ -145,15 +145,17 @@ public function bake($plugin) {
$controllerFileName = $plugin . 'AppController.php';
$out = "<?php\n\n";
+ $out .= "App::uses('AppController', 'Controller');\n\n";
$out .= "class {$plugin}AppController extends AppController {\n\n";
- $out .= "}\n\n";
+ $out .= "}\n";
$this->createFile($this->path . $plugin . DS . 'Controller' . DS . $controllerFileName, $out);
$modelFileName = $plugin . 'AppModel.php';
$out = "<?php\n\n";
+ $out .= "App::uses('AppModel', 'Model');\n\n";
$out .= "class {$plugin}AppModel extends AppModel {\n\n";
- $out .= "}\n\n";
+ $out .= "}\n";
$this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out);
$this->_modifyBootstrap($plugin);
@@ -208,7 +208,8 @@ public function startup(Controller $controller) {
* @param string|array $key Key for the value
* @param mixed $value Value
* @param boolean $encrypt Set to true to encrypt value, false otherwise
- * @param integer|string $expires Can be either Unix timestamp, or date string
+ * @param integer|string $expires Can be either the number of seconds until a cookie
+ * expires, or a strtotime compatible time offset.
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::write
*/
@@ -1153,10 +1153,12 @@ protected function _filterResults(&$results, Model $model, $filtered = array())
}
$linkedModel = $model->{$className};
$filtering[] = $className;
- foreach ($results as &$result) {
+ foreach ($results as $key => &$result) {
$data = $linkedModel->afterFind(array(array($className => $result[$className])), false);
if (isset($data[0][$className])) {
$result[$className] = $data[0][$className];
+ } else {
+ unset($results[$key]);
}
}
}
@@ -977,7 +977,7 @@ protected function _createLinks() {
$plugin = null;
if (is_numeric($assoc)) {
- unset ($this->{$type}[$assoc]);
+ unset($this->{$type}[$assoc]);
$assoc = $value;
$value = array();
@@ -1153,7 +1153,7 @@ public function set($one, $two = null) {
foreach ($fieldSet as $fieldName => $fieldValue) {
if (isset($this->validationErrors[$fieldName])) {
- unset ($this->validationErrors[$fieldName]);
+ unset($this->validationErrors[$fieldName]);
}
if ($modelName === $this->alias) {
@@ -2496,7 +2496,7 @@ public function deleteAll($conditions, $cascade = true, $callbacks = false) {
'fields' => "{$this->alias}.{$this->primaryKey}",
'recursive' => 0), compact('conditions'))
);
- if ($ids === false) {
+ if ($ids === null) {
return false;
}
@@ -232,7 +232,12 @@ protected function _url() {
} elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
$uri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
- $uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
+ $qPosition = strpos($_SERVER['REQUEST_URI'], '?');
+ if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) {
+ $uri = $_SERVER['REQUEST_URI'];
+ } else {
+ $uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
+ }
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
@@ -90,6 +90,10 @@ public function setUp() {
array($out, $out, $in)
);
$this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in));
+
+ if (!defined('ARTICLE_MODEL_CREATED')) {
+ $this->markTestSkipped('Could not run as an Article, Tag or Comment model was already loaded.');
+ }
}
/**
@@ -340,7 +344,6 @@ public function testBakeWithPlugin() {
* @return void
*/
public function testBakeActionsUsingSessions() {
- $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined.');
$result = $this->Task->bakeActions('BakeArticles', null, true);
@@ -379,7 +382,6 @@ public function testBakeActionsUsingSessions() {
* @return void
*/
public function testBakeActionsWithNoSessions() {
- $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined.');
$result = $this->Task->bakeActions('BakeArticles', null, false);
@@ -511,9 +513,7 @@ public function testExecuteIntoAll() {
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute into all could not be run as an Article, Tag or Comment model was already loaded.');
- }
+
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
@@ -531,14 +531,44 @@ public function testExecuteIntoAll() {
}
/**
+ * Test execute() with all and --admin
+ *
+ * @return void
+ */
+ public function testExecuteIntoAllAdmin() {
+ $count = count($this->Task->listAll('test'));
+ if ($count != count($this->fixtures)) {
+ $this->markTestSkipped('Additional tables detected.');
+ }
+
+ $this->Task->connection = 'test';
+ $this->Task->path = '/my/path/';
+ $this->Task->args = array('all');
+ $this->Task->params['admin'] = true;
+
+ $this->Task->Project->expects($this->any())
+ ->method('getPrefix')
+ ->will($this->returnValue('admin_'));
+ $this->Task->expects($this->any())
+ ->method('_checkUnitTest')
+ ->will($this->returnValue(true));
+ $this->Task->Test->expects($this->once())->method('bake');
+
+ $filename = '/my/path/BakeArticlesController.php';
+ $this->Task->expects($this->once())->method('createFile')->with(
+ $filename,
+ $this->stringContains('function admin_index')
+ )->will($this->returnValue(true));
+
+ $this->Task->execute();
+ }
+
+/**
* test that `cake bake controller foos` works.
*
* @return void
*/
public function testExecuteWithController() {
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined');
- }
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
@@ -570,9 +600,6 @@ public static function nameVariations() {
* @return void
*/
public function testExecuteWithControllerNameVariations($name) {
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined.');
- }
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array($name);
@@ -590,9 +617,6 @@ public function testExecuteWithControllerNameVariations($name) {
* @return void
*/
public function testExecuteWithPublicParam() {
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute with public param requires no Article, Tag or Comment model to be defined.');
- }
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
@@ -612,9 +636,6 @@ public function testExecuteWithPublicParam() {
* @return void
*/
public function testExecuteWithControllerAndBoth() {
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute with controller and both requires no Article, Tag or Comment model to be defined.');
- }
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
@@ -634,9 +655,6 @@ public function testExecuteWithControllerAndBoth() {
* @return void
*/
public function testExecuteWithControllerAndAdmin() {
- if (!defined('ARTICLE_MODEL_CREATED')) {
- $this->markTestSkipped('Execute with controller and admin requires no Article, Tag or Comment model to be defined.');
- }
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
@@ -435,6 +435,26 @@ public function testDeleteAllUnknownColumn() {
}
/**
+ * testDeleteAllFailedFind method
+ *
+ * Eg: Behavior callback stops the event, find returns null
+ *
+ * @return void
+ */
+ public function testDeleteAllFailedFind() {
+ $this->loadFixtures('Article');
+ $this->getMock('Article', array('find'), array(), 'ArticleDeleteAll');
+
+ $TestModel = new ArticleDeleteAll();
+ $TestModel->expects($this->once())
+ ->method('find')
+ ->will($this->returnValue(null));
+
+ $result = $TestModel->deleteAll(array('Article.user_id' => 999));
+ $this->assertFalse($result);
+ }
+
+/**
* testRecursiveDel method
*
* @return void
@@ -3007,6 +3007,30 @@ public function testSelfAssociationAfterFind() {
}
/**
+ * Test that afterFind can completely unset data.
+ *
+ * @return void
+ */
+ public function testAfterFindUnset() {
+ $this->loadFixtures('Article', 'Comment', 'User');
+ $model = new CustomArticle();
+ $model->bindModel(array(
+ 'hasMany' => array(
+ 'ModifiedComment' => array(
+ 'className' => 'ModifiedComment',
+ 'foreignKey' => 'article_id',
+ )
+ )
+ ));
+ $model->ModifiedComment->remove = true;
+ $result = $model->find('all');
+ $this->assertTrue(
+ empty($result[0]['ModifiedComment']),
+ 'Zeroith row should be removed by afterFind'
+ );
+ }
+
+/**
* testFindThreadedNoParent method
*
* @return void
@@ -552,6 +552,13 @@ class ModifiedComment extends CakeTestModel {
public $useTable = 'comments';
/**
+ * Property used to toggle filtering of results
+ *
+ * @var boolean
+ */
+ public $remove = false;
+
+/**
* belongsTo property
*
* @var array
@@ -567,6 +574,9 @@ public function afterFind($results, $primary = false) {
if (isset($results[0])) {
$results[0]['Comment']['callback'] = 'Fire';
}
+ if ($this->remove) {
+ return array();
+ }
return $results;
}
@@ -136,6 +136,14 @@ public function testQueryStringAndNamedParams() {
$_SERVER['REQUEST_URI'] = '/tasks/index/page:1/?ts=123456';
$request = new CakeRequest();
$this->assertEquals('tasks/index/page:1/', $request->url);
+
+ $_SERVER['REQUEST_URI'] = '/some/path?url=http://cakephp.org';
+ $request = new CakeRequest();
+ $this->assertEquals('some/path', $request->url);
+
+ $_SERVER['REQUEST_URI'] = FULL_BASE_URL . '/other/path?url=http://cakephp.org';
+ $request = new CakeRequest();
+ $this->assertEquals('other/path', $request->url);
}
/**
@@ -367,6 +367,12 @@ public function testNiceShort() {
$time = time() + DAY;
$this->assertEquals('Tomorrow, ' . date('H:i', $time), $this->Time->niceShort($time));
+ $time = strtotime('+6 days');
+ $this->assertEquals('On ' . date('l F d, H:i', $time), $this->Time->niceShort($time));
+
+ $time = strtotime('-6 days');
+ $this->assertEquals(date('l F d, H:i', $time), $this->Time->niceShort($time));
+
date_default_timezone_set('Europe/London');
$result = $this->Time->niceShort('2005-01-15 10:00:00', new DateTimeZone('Europe/Brussels'));
$this->assertEquals('Jan 15th 2005, 11:00', $result);
@@ -56,7 +56,7 @@ class CakeTime {
* @var string
* @see CakeTime::niceShort()
*/
- public static $niceShortFormat = '%d/%m, %H:%M';
+ public static $niceShortFormat = '%B %d, %H:%M';
/**
* The format to use when formatting a time using `CakeTime::timeAgoInWords()`
@@ -101,7 +101,7 @@ public static function build($input, $options = array()) {
} elseif (file_exists($input)) {
return self::_loadXml(file_get_contents($input), $options);
} elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
- $socket = new HttpSocket();
+ $socket = new HttpSocket(array('request' => array('redirect' => 10)));
$response = $socket->get($input);
if (!$response->isOk()) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
Oops, something went wrong.

0 comments on commit b2cbeee

Please sign in to comment.