mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 23:53:38 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* SchemaShellTest Test file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* 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.
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.Console.Command
|
||||
* @since CakePHP v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ShellDispatcher', 'Console');
|
||||
|
@ -31,17 +30,10 @@ App::uses('SchemaShell', 'Console/Command');
|
|||
*/
|
||||
class SchemaShellTestSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'MyApp'
|
||||
*/
|
||||
public $name = 'SchemaShellTest';
|
||||
|
||||
/**
|
||||
* connection property
|
||||
*
|
||||
* @var string 'test'
|
||||
* @var string
|
||||
*/
|
||||
public $connection = 'test';
|
||||
|
||||
|
@ -78,6 +70,14 @@ class SchemaShellTestSchema extends CakeSchema {
|
|||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
||||
);
|
||||
|
||||
public $newone = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'testit' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +92,9 @@ class SchemaShellTest extends CakeTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = array('core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author',
|
||||
'core.comment', 'core.test_plugin_comment'
|
||||
public $fixtures = array(
|
||||
'core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author',
|
||||
'core.comment', 'core.test_plugin_comment', 'core.aco', 'core.aro', 'core.aros_aco',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -134,7 +135,7 @@ class SchemaShellTest extends CakeTestCase {
|
|||
public function testStartup() {
|
||||
$this->Shell->startup();
|
||||
$this->assertTrue(isset($this->Shell->Schema));
|
||||
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
|
||||
$this->assertInstanceOf('CakeSchema', $this->Shell->Schema);
|
||||
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
|
||||
$this->assertEquals('schema.php', $this->Shell->Schema->file);
|
||||
|
||||
|
@ -294,7 +295,7 @@ class SchemaShellTest extends CakeTestCase {
|
|||
$this->Shell->Schema->path = TMP;
|
||||
$this->Shell->Schema->expects($this->never())->method('read');
|
||||
|
||||
$result = $this->Shell->generate();
|
||||
$this->Shell->generate();
|
||||
unlink(TMP . 'schema.php');
|
||||
}
|
||||
|
||||
|
@ -362,6 +363,90 @@ class SchemaShellTest extends CakeTestCase {
|
|||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate with specific models
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateModels() {
|
||||
App::build(array(
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
), App::RESET);
|
||||
CakePlugin::load('TestPlugin');
|
||||
|
||||
$this->db->cacheSources = false;
|
||||
$this->Shell->params = array(
|
||||
'plugin' => 'TestPlugin',
|
||||
'connection' => 'test',
|
||||
'models' => 'TestPluginComment',
|
||||
'force' => false,
|
||||
'overwrite' => true
|
||||
);
|
||||
$this->Shell->startup();
|
||||
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
||||
|
||||
$this->Shell->generate();
|
||||
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
||||
$contents = $this->file->read();
|
||||
|
||||
$this->assertRegExp('/class TestPluginSchema/', $contents);
|
||||
$this->assertRegExp('/public \$test_plugin_comments/', $contents);
|
||||
$this->assertNotRegExp('/public \$authors/', $contents);
|
||||
$this->assertNotRegExp('/public \$auth_users/', $contents);
|
||||
$this->assertNotRegExp('/public \$posts/', $contents);
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate with excluded tables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateExclude() {
|
||||
Configure::write('Acl.database', 'test');
|
||||
$this->db->cacheSources = false;
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test',
|
||||
'force' => false,
|
||||
'models' => 'Aro, Aco, Permission',
|
||||
'overwrite' => true,
|
||||
'exclude' => 'acos, aros',
|
||||
);
|
||||
$this->Shell->startup();
|
||||
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
||||
|
||||
$this->Shell->generate();
|
||||
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
||||
$contents = $this->file->read();
|
||||
|
||||
$this->assertNotContains('public $acos = array(', $contents);
|
||||
$this->assertNotContains('public $aros = array(', $contents);
|
||||
$this->assertContains('public $aros_acos = array(', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test schema run create with --yes option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateOptionYes() {
|
||||
$this->Shell = $this->getMock(
|
||||
'SchemaShell',
|
||||
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
|
||||
array(&$this->Dispatcher)
|
||||
);
|
||||
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test',
|
||||
'yes' => true,
|
||||
);
|
||||
$this->Shell->args = array('i18n');
|
||||
$this->Shell->expects($this->never())->method('in');
|
||||
$this->Shell->expects($this->exactly(2))->method('_run');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test schema run create with no table args.
|
||||
*
|
||||
|
@ -394,15 +479,15 @@ class SchemaShellTest extends CakeTestCase {
|
|||
public function testCreateWithTableArgs() {
|
||||
$db = ConnectionManager::getDataSource('test');
|
||||
$sources = $db->listSources();
|
||||
if (in_array('acos', $sources)) {
|
||||
$this->markTestSkipped('acos table already exists, cannot try to create it again.');
|
||||
if (in_array('i18n', $sources)) {
|
||||
$this->markTestSkipped('i18n table already exists, cannot try to create it again.');
|
||||
}
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test',
|
||||
'name' => 'DbAcl',
|
||||
'name' => 'I18n',
|
||||
'path' => APP . 'Config' . DS . 'Schema'
|
||||
);
|
||||
$this->Shell->args = array('DbAcl', 'acos');
|
||||
$this->Shell->args = array('I18n', 'i18n');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||
$this->Shell->create();
|
||||
|
@ -410,12 +495,10 @@ class SchemaShellTest extends CakeTestCase {
|
|||
$db = ConnectionManager::getDataSource('test');
|
||||
$db->cacheSources = false;
|
||||
$sources = $db->listSources();
|
||||
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources), 'acos should be present.');
|
||||
$this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources), 'aros should not be found.');
|
||||
$this->assertFalse(in_array('aros_acos', $sources), 'aros_acos should not be found.');
|
||||
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources), 'i18n should be present.');
|
||||
|
||||
$schema = new DbAclSchema();
|
||||
$db->execute($db->dropSchema($schema, 'acos'));
|
||||
$schema = new I18nSchema();
|
||||
$db->execute($db->dropSchema($schema, 'i18n'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -436,8 +519,66 @@ class SchemaShellTest extends CakeTestCase {
|
|||
);
|
||||
$this->Shell->args = array('SchemaShellTest', 'articles');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||
$this->Shell->expects($this->once())->method('_run')
|
||||
$this->Shell->expects($this->any())
|
||||
->method('in')
|
||||
->will($this->returnValue('y'));
|
||||
$this->Shell->expects($this->once())
|
||||
->method('_run')
|
||||
->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
|
||||
|
||||
$this->Shell->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* test run update with a table arg. and checks that a CREATE statement is issued
|
||||
* table creation
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateWithTableCreate() {
|
||||
$this->Shell = $this->getMock(
|
||||
'SchemaShell',
|
||||
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
|
||||
array(&$this->Dispatcher)
|
||||
);
|
||||
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test',
|
||||
'force' => true
|
||||
);
|
||||
$this->Shell->args = array('SchemaShellTest', 'newone');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->expects($this->any())
|
||||
->method('in')
|
||||
->will($this->returnValue('y'));
|
||||
$this->Shell->expects($this->once())
|
||||
->method('_run')
|
||||
->with($this->arrayHasKey('newone'), 'update', $this->isInstanceOf('CakeSchema'));
|
||||
|
||||
$this->Shell->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* test run update with --yes option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateWithOptionYes() {
|
||||
$this->Shell = $this->getMock(
|
||||
'SchemaShell',
|
||||
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
|
||||
array(&$this->Dispatcher)
|
||||
);
|
||||
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test',
|
||||
'force' => true,
|
||||
'yes' => true,
|
||||
);
|
||||
$this->Shell->args = array('SchemaShellTest', 'articles');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->expects($this->never())->method('in');
|
||||
$this->Shell->expects($this->once())
|
||||
->method('_run')
|
||||
->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
|
||||
|
||||
$this->Shell->update();
|
||||
|
@ -463,6 +604,71 @@ class SchemaShellTest extends CakeTestCase {
|
|||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that underscored names also result in CamelCased class names
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testName() {
|
||||
App::build(array(
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
));
|
||||
CakePlugin::load('TestPlugin');
|
||||
$this->Shell->params = array(
|
||||
'plugin' => 'TestPlugin',
|
||||
'connection' => 'test',
|
||||
'name' => 'custom_names',
|
||||
'force' => false,
|
||||
'overwrite' => true,
|
||||
);
|
||||
$this->Shell->startup();
|
||||
if (file_exists($this->Shell->Schema->path . DS . 'custom_names.php')) {
|
||||
unlink($this->Shell->Schema->path . DS . 'custom_names.php');
|
||||
}
|
||||
$this->Shell->generate();
|
||||
|
||||
$contents = file_get_contents($this->Shell->Schema->path . DS . 'custom_names.php');
|
||||
$this->assertRegExp('/class CustomNamesSchema/', $contents);
|
||||
unlink($this->Shell->Schema->path . DS . 'custom_names.php');
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that passing name and file creates the passed filename with the
|
||||
* passed class name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNameAndFile() {
|
||||
App::build(array(
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
));
|
||||
CakePlugin::load('TestPlugin');
|
||||
$this->Shell->params = array(
|
||||
'plugin' => 'TestPlugin',
|
||||
'connection' => 'test',
|
||||
'name' => 'custom_name',
|
||||
'file' => 'other_name',
|
||||
'force' => false,
|
||||
'overwrite' => true,
|
||||
);
|
||||
$this->Shell->startup();
|
||||
$file = $this->Shell->Schema->path . DS . 'other_name.php';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
$this->Shell->generate();
|
||||
|
||||
$this->assertFileExists($file);
|
||||
$contents = file_get_contents($file);
|
||||
$this->assertRegExp('/class CustomNameSchema/', $contents);
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that using Plugin.name with write.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue