Permalink
Browse files

Merge branch 'master' into 2.3

  • Loading branch information...
2 parents f963e37 + 27e2132 commit d94cdc67fe40f3c79ac59f70aa2fd2eacc7a5ce1 @markstory markstory committed Jul 28, 2012
@@ -479,6 +479,7 @@ public function generateConstructor($type, $fullClassName, $plugin) {
*/
public function generateUses($type, $realType, $className) {
$uses = array();
+ $type = strtolower($type);
if ($type == 'component') {
$uses[] = array('ComponentCollection', 'Controller');
$uses[] = array('Component', 'Controller');
@@ -565,10 +565,7 @@ public static function user($key = null) {
if ($key === null) {
return $user;
}
- if ($value = Hash::get($user, $key)) {
- return $value;
- }
- return null;
+ return Hash::get($user, $key);
}
/**

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -2953,11 +2953,24 @@ public function createSchema($schema, $tableName = null) {
$primary = null;
$table = $this->fullTableName($curTable);
+ $primaryCount = 0;
+ foreach ($columns as $col) {
+ if (isset($col['key']) && $col['key'] === 'primary') {
+ $primaryCount++;
+ }
+ }
+
foreach ($columns as $name => $col) {
if (is_string($col)) {
$col = array('type' => $col);
}
- if (isset($col['key']) && $col['key'] === 'primary') {
+ $isPrimary = isset($col['key']) && $col['key'] === 'primary';
+ // Multi-column primary keys are not supported.
+ if ($isPrimary && $primaryCount > 1) {
+ unset($col['key']);
+ $isPrimary = false;
+ }
+ if ($isPrimary) {
$primary = $name;
}
if ($name !== 'indexes' && $name !== 'tableParameters') {
@@ -182,7 +182,10 @@ public static function defaultRouteClass($routeClass = null) {
* @throws RouterException
*/
protected static function _validateRouteClass($routeClass) {
- if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) {
+ if (
+ $routeClass != 'CakeRoute' &&
+ (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute'))
+ ) {
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
}
return $routeClass;
@@ -225,6 +225,15 @@ public function testH() {
'n' => ' '
);
$this->assertEquals($expected, $result);
+
+ // Test that boolean values are not converted to strings
+ $result = h(false);
+ $this->assertFalse($result);
+
+ $arr = array('foo' => false, 'bar' => true);
+ $result = h($arr);
+ $this->assertFalse($result['foo']);
+ $this->assertTrue($result['bar']);
$obj = new stdClass();
$result = h($obj);
@@ -117,10 +117,10 @@ public function testListAll() {
$this->Task->connection = 'test';
$this->Task->interactive = true;
- $this->Task->expects($this->at(1))->method('out')->with('1. BakeArticles');
- $this->Task->expects($this->at(2))->method('out')->with('2. BakeArticlesBakeTags');
- $this->Task->expects($this->at(3))->method('out')->with('3. BakeComments');
- $this->Task->expects($this->at(4))->method('out')->with('4. BakeTags');
+ $this->Task->expects($this->at(2))->method('out')->with(' 1. BakeArticles');
+ $this->Task->expects($this->at(3))->method('out')->with(' 2. BakeArticlesBakeTags');
+ $this->Task->expects($this->at(4))->method('out')->with(' 3. BakeComments');
+ $this->Task->expects($this->at(5))->method('out')->with(' 4. BakeTags');
$expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');
$result = $this->Task->listAll('test');
@@ -491,6 +491,8 @@ public function testBakeComponentTest() {
$result = $this->Task->bake('Component', 'Example');
+ $this->assertContains("App::uses('Component', 'Controller')", $result);
+ $this->assertContains("App::uses('ComponentCollection', 'Controller')", $result);
$this->assertContains("App::uses('ExampleComponent', 'Controller/Component')", $result);
$this->assertContains('class ExampleComponentTest extends CakeTestCase', $result);
@@ -1269,6 +1269,7 @@ public function testUser() {
'id' => '1',
'name' => 'Members'
),
+ 'is_admin' => false,
));
$this->Auth->Session->write('Auth', $data);
@@ -1286,5 +1287,8 @@ public function testUser() {
$result = $this->Auth->user('Company.invalid');
$this->assertEquals(null, $result);
+
+ $result = $this->Auth->user('is_admin');
+ $this->assertFalse($result);
}
}
@@ -839,6 +839,45 @@ public function testDescribeGettingFieldParameters() {
}
/**
+ * Test that two columns with key => primary doesn't create invalid sql.
+ *
+ * @return void
+ */
+ public function testTwoColumnsWithPrimaryKey() {
+ $schema = new CakeSchema(array(
+ 'connection' => 'test',
+ 'roles_users' => array(
+ 'role_id' => array(
+ 'type' => 'integer',
+ 'null' => false,
+ 'default' => null,
+ 'key' => 'primary'
+ ),
+ 'user_id' => array(
+ 'type' => 'integer',
+ 'null' => false,
+ 'default' => null,
+ 'key' => 'primary'
+ ),
+ 'indexes' => array(
+ 'user_role_index' => array(
+ 'column' => array('role_id', 'user_id'),
+ 'unique' => 1
+ ),
+ 'user_index' => array(
+ 'column' => 'user_id',
+ 'unique' => 0
+ )
+ ),
+ )
+ ));
+
+ $result = $this->Dbo->createSchema($schema);
+ $this->assertContains('`role_id` int(11) NOT NULL,', $result);
+ $this->assertContains('`user_id` int(11) NOT NULL,', $result);
+ }
+
+/**
* Tests that listSources method sends the correct query and parses the result accordingly
* @return void
*/
@@ -1,9 +1,5 @@
<?php
/**
- * DebuggerTest file
- *
- * PHP 5
- *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -12,7 +8,6 @@
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
- * @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
@@ -5125,6 +5125,45 @@ public function testDateTimeWithBogusData() {
}
/**
+ * testDateTimeEmptyAsArray
+ *
+ * @return void
+ */
+ public function testDateTimeEmptyAsArray() {
+ $result = $this->Form->dateTime('Contact.date',
+ 'DMY',
+ '12',
+ array(
+ 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
+ 'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
+ )
+ )
+ );
+
+ $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
+ $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
+ $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
+ $this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
+ $this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
+ $this->assertNotRegExp('/<option value=""><\/option>/', $result);
+
+ $result = $this->Form->dateTime('Contact.date',
+ 'DMY',
+ '12',
+ array(
+ 'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
+ )
+ );
+
+ $this->assertRegExp('/<option value="">DAY<\/option>/', $result);
+ $this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
+ $this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
+ $this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
+ $this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
+ $this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
+ }
+
+/**
* testFormDateTimeMulti method
*
* test multiple datetime element generation
@@ -710,8 +710,14 @@ public function outputError($data) {
$files = $this->trace(array('start' => $data['start'], 'format' => 'points'));
$code = '';
- if (isset($files[1]['file'])) {
- $code = $this->excerpt($files[1]['file'], $files[1]['line'] - 1, 1);
+ $file = null;
+ if (isset($files[0]['file'])) {
+ $file = $files[0];
+ } elseif (isset($files[1]['file'])) {
+ $file = $files[1];
+ }
+ if ($file) {
+ $code = $this->excerpt($file['file'], $file['line'] - 1, 1);
}
$trace = $this->trace(array('start' => $data['start'], 'depth' => '20'));
$insertOpts = array('before' => '{:', 'after' => '}');
@@ -720,7 +726,7 @@ public function outputError($data) {
$info = '';
foreach ((array)$data['context'] as $var => $value) {
- $context[] = "\${$var} = " . $this->exportVar($value, 1);
+ $context[] = "\${$var} = " . $this->exportVar($value, 3);
}
switch ($this->_outputFormat) {
View
@@ -691,7 +691,7 @@ public function value($options = array(), $field = null, $key = 'value') {
$data = $this->request->data;
$entity = $this->entity();
- if (!empty($data) && !empty($entity)) {
+ if (!empty($data) && is_array($data) && !empty($entity)) {
$result = Hash::get($data, implode('.', $entity));
}
@@ -2259,6 +2259,17 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
}
}
+ if (is_array($attributes['empty'])) {
+ $attributes['empty'] += array(
+ 'month' => true, 'year' => true, 'day' => true,
+ 'hour' => true, 'minute' => true, 'meridian' => true
+ );
+ foreach ($elements as $element) {
+ $selectAttrName = 'select' . $element . 'Attr';
+ ${$selectAttrName}['empty'] = $attributes['empty'][strtolower($element)];
+ }
+ }
+
$selects = array();
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
switch ($char) {
View
@@ -175,6 +175,8 @@ function h($text, $double = true, $charset = null) {
} else {
$text = '(object)' . get_class($text);
}
+ } elseif (is_bool($text)) {
+ return $text;
}
static $defaultCharset = false;

0 comments on commit d94cdc6

Please sign in to comment.