Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,20 +2,18 @@
/**
* Test for Schema database management
*
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model
* @since CakePHP(tm) v 1.2.0.5550
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeSchema', 'Model');
@ -28,17 +26,10 @@ App::uses('CakeTestFixture', 'TestSuite/Fixture');
*/
class MyAppSchema extends CakeSchema {
/**
* name property
*
* @var string 'MyApp'
*/
public $name = 'MyApp';
/**
* connection property
*
* @var string 'test'
* @var string
*/
public $connection = 'test';
@ -83,24 +74,6 @@ class MyAppSchema extends CakeSchema {
*/
protected $_foo = array('bar');
/**
* setup method
*
* @param mixed $version
* @return void
*/
public function setup($version) {
}
/**
* teardown method
*
* @param mixed $version
* @return void
*/
public function teardown($version) {
}
/**
* getVar method
*
@ -126,7 +99,7 @@ class TestAppSchema extends CakeSchema {
/**
* name property
*
* @var string 'MyApp'
* @var string
*/
public $name = 'MyApp';
@ -136,7 +109,7 @@ class TestAppSchema extends CakeSchema {
* @var array
*/
public $comments = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0,'key' => 'primary'),
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null' => false),
'user_id' => array('type' => 'integer', 'null' => false),
'comment' => array('type' => 'text', 'null' => true, 'default' => null),
@ -198,6 +171,8 @@ class TestAppSchema extends CakeSchema {
public $datatypes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'),
'huge_int' => array('type' => 'biginteger'),
'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array()
@ -230,17 +205,10 @@ class TestAppSchema extends CakeSchema {
*/
class SchemaPost extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaPost'
*/
public $name = 'SchemaPost';
/**
* useTable property
*
* @var string 'posts'
* @var string
*/
public $useTable = 'posts';
@ -266,17 +234,10 @@ class SchemaPost extends CakeTestModel {
*/
class SchemaComment extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaComment'
*/
public $name = 'SchemaComment';
/**
* useTable property
*
* @var string 'comments'
* @var string
*/
public $useTable = 'comments';
@ -295,17 +256,10 @@ class SchemaComment extends CakeTestModel {
*/
class SchemaTag extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaTag'
*/
public $name = 'SchemaTag';
/**
* useTable property
*
* @var string 'tags'
* @var string
*/
public $useTable = 'tags';
@ -324,17 +278,10 @@ class SchemaTag extends CakeTestModel {
*/
class SchemaDatatype extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaDatatype'
*/
public $name = 'SchemaDatatype';
/**
* useTable property
*
* @var string 'datatypes'
* @var string
*/
public $useTable = 'datatypes';
}
@ -347,17 +294,9 @@ class SchemaDatatype extends CakeTestModel {
* its source cache populated - I.e. if the test is run within a group
*
* @uses CakeTestModel
* @package
* @package Cake.Test.Case.Model
*/
class Testdescribe extends CakeTestModel {
/**
* name property
*
* @var string 'Testdescribe'
*/
public $name = 'Testdescribe';
}
/**
@ -367,24 +306,17 @@ class Testdescribe extends CakeTestModel {
*/
class SchemaCrossDatabase extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaCrossDatabase'
*/
public $name = 'SchemaCrossDatabase';
/**
* useTable property
*
* @var string 'posts'
* @var string
*/
public $useTable = 'cross_database';
/**
* useDbConfig property
*
* @var string 'test2'
* @var string
*/
public $useDbConfig = 'test2';
}
@ -399,13 +331,14 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'CrossDatabase'
* @var string
*/
public $name = 'CrossDatabase';
/**
* table property
*
* @var string
*/
public $table = 'cross_database';
@ -437,13 +370,6 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
*/
class SchemaPrefixAuthUser extends CakeTestModel {
/**
* name property
*
* @var string
*/
public $name = 'SchemaPrefixAuthUser';
/**
* table prefix
*
@ -510,25 +436,7 @@ class CakeSchemaTest extends CakeTestCase {
*/
public function testSchemaName() {
$Schema = new CakeSchema();
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $Schema->name);
Configure::write('App.dir', 'Some.name.with.dots');
$Schema = new CakeSchema();
$this->assertEquals('SomeNameWithDots', $Schema->name);
Configure::write('App.dir', 'Some-name-with-dashes');
$Schema = new CakeSchema();
$this->assertEquals('SomeNameWithDashes', $Schema->name);
Configure::write('App.dir', 'Some name with spaces');
$Schema = new CakeSchema();
$this->assertEquals('SomeNameWithSpaces', $Schema->name);
Configure::write('App.dir', 'Some,name;with&weird=characters');
$Schema = new CakeSchema();
$this->assertEquals('SomeNameWithWeirdCharacters', $Schema->name);
Configure::write('App.dir', 'app');
$this->assertEquals('App', $Schema->name);
}
/**
@ -587,7 +495,6 @@ class CakeSchemaTest extends CakeTestCase {
/**
* testSchemaReadWithAppModel method
*
* @access public
* @return void
*/
public function testSchemaReadWithAppModel() {
@ -595,7 +502,7 @@ class CakeSchemaTest extends CakeTestCase {
ConnectionManager::drop('default');
ConnectionManager::create('default', $connections['test']);
try {
$read = $this->Schema->read(array(
$this->Schema->read(array(
'connection' => 'default',
'name' => 'TestApp',
'models' => array('AppModel')
@ -637,8 +544,6 @@ class CakeSchemaTest extends CakeTestCase {
$config = ConnectionManager::getDataSource('test')->config;
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
$model = new SchemaPrefixAuthUser();
$Schema = new CakeSchema();
$read = $Schema->read(array(
'connection' => 'test',
@ -762,6 +667,39 @@ class CakeSchemaTest extends CakeTestCase {
);
$result = $this->Schema->generateTable('posts', $posts);
$this->assertRegExp('/public \$posts/', $result);
$posts = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext')
)
);
$result = $this->Schema->generateTable('fields', $posts);
$this->assertRegExp('/public \$fields/', $result);
$this->assertRegExp('/\'type\' \=\> \'fulltext\'/', $result);
}
/**
* test that tables with unsupported name are not getting through
*
* @return void
*/
public function testGenerateInvalidTable() {
$invalidTableName = 'invalid name !@#$%^&*()';
$expectedException = "Invalid table name '{$invalidTableName}'";
try{
$this->Schema->generateTable($invalidTableName, array());
$this->fail("Expected exception \"{$expectedException}\" not thrown");
} catch (Exception $e) {
$this->assertEquals($expectedException, $e->getMessage());
}
}
/**
@ -848,13 +786,13 @@ class CakeSchemaTest extends CakeTestCase {
$compare = $New->compare($this->Schema, $tables);
$expected = array(
'ratings' => array(
'add' => array(
'create' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null, 'after' => 'id'),
'model' => array('type' => 'varchar', 'null' => false, 'default' => null, 'after' => 'foreign_key'),
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null, 'after' => 'model'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => null, 'after' => 'value'),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null, 'after' => 'created'),
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null),
'model' => array('type' => 'varchar', 'null' => false, 'default' => null),
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null),
'created' => array('type' => 'datetime', 'null' => false, 'default' => null),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
)
@ -1031,6 +969,63 @@ class CakeSchemaTest extends CakeTestCase {
$this->assertEquals($expected, $compare, 'Invalid SQL, datetime does not have length');
}
/**
* Test comparing with field length/limit changed from some non-default value to the default
*
* @return void
*/
public function testCompareLimitToDefault() {
$old = array(
'posts' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 1, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false, 'limit' => 5),
'title' => array('type' => 'string', 'null' => true, 'length' => 45),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array(
'charset' => 'latin1',
'collate' => 'latin1_general_ci'
)
),
);
$new = array(
'posts' => array(
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'varchar', 'null' => true),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array(
'charset' => 'latin1',
'collate' => 'latin1_general_ci'
)
),
);
$compare = $this->Schema->compare($old, $new);
$expected = array(
'posts' => array(
'change' => array(
'id' => array(
'type' => 'integer',
'null' => false,
'key' => 'primary'
),
'author_id' => array(
'type' => 'integer',
'null' => false,
),
'title' => array(
'type' => 'varchar',
'null' => true,
)
)
),
);
$this->assertEquals($expected, $compare, 'Invalid SQL, field length change not detected');
}
/**
* testSchemaLoading method
*