code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function testGetPluginDataSource() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$name = 'test_source';
$config = array('datasource' => 'TestPlugin.TestSource');
$connection = ConnectionManager::create($name, $config);
$this->assertTrue(class_exists('TestSource'));
$this->assertEqual($connection->configKeyName, $name);
$this->assertEqual($connection->config, $config);
App::build();
} | testGetPluginDataSource method
@access public
@return void | testGetPluginDataSource | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testGetPluginDataSourceAndPluginDriver() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$name = 'test_plugin_source_and_driver';
$config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'TestPlugin.TestDriver');
$connection = ConnectionManager::create($name, $config);
$this->assertTrue(class_exists('TestSource'));
$this->assertTrue(class_exists('TestDriver'));
$this->assertEqual($connection->configKeyName, $name);
$this->assertEqual($connection->config, $config);
App::build();
} | testGetPluginDataSourceAndPluginDriver method
@access public
@return void | testGetPluginDataSourceAndPluginDriver | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testGetLocalDataSourceAndPluginDriver() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$name = 'test_local_source_and_plugin_driver';
$config = array('datasource' => 'dbo', 'driver' => 'TestPlugin.DboDummy');
$connection = ConnectionManager::create($name, $config);
$this->assertTrue(class_exists('DboSource'));
$this->assertTrue(class_exists('DboDummy'));
$this->assertEqual($connection->configKeyName, $name);
App::build();
} | testGetLocalDataSourceAndPluginDriver method
@access public
@return void | testGetLocalDataSourceAndPluginDriver | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testGetPluginDataSourceAndLocalDriver() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS)
));
$name = 'test_plugin_source_and_local_driver';
$config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'local_driver');
$connection = ConnectionManager::create($name, $config);
$this->assertTrue(class_exists('TestSource'));
$this->assertTrue(class_exists('TestLocalDriver'));
$this->assertEqual($connection->configKeyName, $name);
$this->assertEqual($connection->config, $config);
App::build();
} | testGetPluginDataSourceAndLocalDriver method
@access public
@return void | testGetPluginDataSourceAndLocalDriver | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testSourceList() {
$sources = ConnectionManager::sourceList();
$this->assertTrue(count($sources) >= 1);
$connections = array('default', 'test', 'test_suite');
$this->assertTrue(count(array_intersect($sources, $connections)) >= 1);
} | testSourceList method
@access public
@return void | testSourceList | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testGetSourceName() {
$connections = ConnectionManager::enumConnectionObjects();
$name = key($connections);
$source = ConnectionManager::getDataSource($name);
$result = ConnectionManager::getSourceName($source);
$this->assertEqual($result, $name);
$source =& new StdClass();
$result = ConnectionManager::getSourceName($source);
$this->assertEqual($result, null);
} | testGetSourceName method
@access public
@return void | testGetSourceName | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testLoadDataSource() {
$connections = array(
array('classname' => 'DboMysql', 'filename' => 'dbo' . DS . 'dbo_mysql'),
array('classname' => 'DboMysqli', 'filename' => 'dbo' . DS . 'dbo_mysqli'),
array('classname' => 'DboMssql', 'filename' => 'dbo' . DS . 'dbo_mssql'),
array('classname' => 'DboOracle', 'filename' => 'dbo' . DS . 'dbo_oracle'),
);
foreach ($connections as $connection) {
$exists = class_exists($connection['classname']);
$loaded = ConnectionManager::loadDataSource($connection);
$this->assertEqual($loaded, !$exists, "%s Failed loading the {$connection['classname']} datasource");
}
$connection = array('classname' => 'NonExistentDataSource', 'filename' => 'non_existent');
$this->expectError(new PatternExpectation('/Unable to import DataSource class/i'));
$loaded = ConnectionManager::loadDataSource($connection);
$this->assertEqual($loaded, null);
} | testLoadDataSource method
@access public
@return void | testLoadDataSource | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testCreateDataSourceWithIntegrationTests() {
$name = 'test_created_connection';
$connections = ConnectionManager::enumConnectionObjects();
$this->assertTrue(count(array_keys($connections) >= 1));
$source = ConnectionManager::getDataSource(key($connections));
$this->assertTrue(is_object($source));
$config = $source->config;
$connection = ConnectionManager::create($name, $config);
$this->assertTrue(is_object($connection));
$this->assertEqual($name, $connection->configKeyName);
$this->assertEqual($name, ConnectionManager::getSourceName($connection));
$source = ConnectionManager::create(null, array());
$this->assertEqual($source, null);
$source = ConnectionManager::create('another_test', array());
$this->assertEqual($source, null);
$config = array('classname' => 'DboMysql', 'filename' => 'dbo' . DS . 'dbo_mysql');
$source = ConnectionManager::create(null, $config);
$this->assertEqual($source, null);
} | testCreateDataSource method
@access public
@return void | testCreateDataSourceWithIntegrationTests | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function testConnectionData() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS)
));
$expected = array(
'filename' => 'test2_source',
'classname' => 'Test2Source',
'parent' => '',
'plugin' => ''
);
ConnectionManager::create('connection1', array('datasource' => 'Test2'));
$connections = ConnectionManager::enumConnectionObjects();
$this->assertEqual($expected, $connections['connection1']);
ConnectionManager::create('connection2', array('datasource' => 'Test2Source'));
$connections = ConnectionManager::enumConnectionObjects();
$this->assertEqual($expected, $connections['connection2']);
ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.Test'));
$connections = ConnectionManager::enumConnectionObjects();
$expected['filename'] = 'test_source';
$expected['classname'] = 'TestSource';
$expected['plugin'] = 'TestPlugin';
$this->assertEqual($expected, $connections['connection3']);
ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource'));
$connections = ConnectionManager::enumConnectionObjects();
$this->assertEqual($expected, $connections['connection4']);
ConnectionManager::create('connection5', array('datasource' => 'Test2Other'));
$connections = ConnectionManager::enumConnectionObjects();
$expected['filename'] = 'test2_other_source';
$expected['classname'] = 'Test2OtherSource';
$expected['plugin'] = '';
$this->assertEqual($expected, $connections['connection5']);
ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource'));
$connections = ConnectionManager::enumConnectionObjects();
$this->assertEqual($expected, $connections['connection6']);
ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOther'));
$connections = ConnectionManager::enumConnectionObjects();
$expected['filename'] = 'test_other_source';
$expected['classname'] = 'TestOtherSource';
$expected['plugin'] = 'TestPlugin';
$this->assertEqual($expected, $connections['connection7']);
ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource'));
$connections = ConnectionManager::enumConnectionObjects();
$this->assertEqual($expected, $connections['connection8']);
} | testConnectionData method
@access public
@return void | testConnectionData | php | Datawalke/Coordino | cake/tests/cases/libs/model/connection_manager.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php | MIT |
function bindNode($ref = null) {
if (Configure::read('DbAclbindMode') == 'string') {
return 'ROOT/admins/Gandalf';
} elseif (Configure::read('DbAclbindMode') == 'array') {
return array('DbAroTest' => array('DbAroTest.model' => 'AuthUser', 'DbAroTest.foreign_key' => 2));
}
} | bindNode method
@param mixed $ref
@access public
@return void | bindNode | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function __construct() {
$this->Aro =& new DbAroTest();
$this->Aro->Permission =& new DbPermissionTest();
$this->Aco =& new DbAcoTest();
$this->Aro->Permission =& new DbPermissionTest();
} | construct method
@access private
@return void | __construct | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function setUp() {
Configure::write('Acl.classname', 'DbAclTest');
Configure::write('Acl.database', 'test_suite');
} | setUp method
@access public
@return void | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function testNode() {
$Aco =& new DbAcoTest();
$result = Set::extract($Aco->node('Controller1'), '{n}.DbAcoTest.id');
$expected = array(2, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller1/action1'), '{n}.DbAcoTest.id');
$expected = array(3, 2, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller2/action1'), '{n}.DbAcoTest.id');
$expected = array(7, 6, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller1/action2'), '{n}.DbAcoTest.id');
$expected = array(5, 2, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller1/action1/record1'), '{n}.DbAcoTest.id');
$expected = array(4, 3, 2, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller2/action1/record1'), '{n}.DbAcoTest.id');
$expected = array(8, 7, 6, 1);
$this->assertEqual($result, $expected);
$result = Set::extract($Aco->node('Controller2/action3'), '{n}.DbAcoTest.id');
$this->assertFalse($result);
$result = Set::extract($Aco->node('Controller2/action3/record5'), '{n}.DbAcoTest.id');
$this->assertFalse($result);
$result = $Aco->node('');
$this->assertEqual($result, null);
} | testNode method
@access public
@return void | testNode | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function testNodeWithDuplicatePathSegments() {
$Aco =& new DbAcoTest();
$nodes = $Aco->node('ROOT/Users');
$this->assertEqual($nodes[0]['DbAcoTest']['parent_id'], 1, 'Parent id does not point at ROOT. %s');
} | test that node() doesn't dig deeper than it should.
@return void | testNodeWithDuplicatePathSegments | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function testNodeArrayFind() {
$Aro = new DbAroTest();
Configure::write('DbAclbindMode', 'string');
$result = Set::extract($Aro->node(array('DbAroUserTest' => array('id' => '1', 'foreign_key' => '1'))), '{n}.DbAroTest.id');
$expected = array(3, 2, 1);
$this->assertEqual($result, $expected);
Configure::write('DbAclbindMode', 'array');
$result = Set::extract($Aro->node(array('DbAroUserTest' => array('id' => 4, 'foreign_key' => 2))), '{n}.DbAroTest.id');
$expected = array(4);
$this->assertEqual($result, $expected);
} | testNodeArrayFind method
@access public
@return void | testNodeArrayFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function testNodeObjectFind() {
$Aro = new DbAroTest();
$Model = new DbAroUserTest();
$Model->id = 1;
$result = Set::extract($Aro->node($Model), '{n}.DbAroTest.id');
$expected = array(3, 2, 1);
$this->assertEqual($result, $expected);
$Model->id = 2;
$result = Set::extract($Aro->node($Model), '{n}.DbAroTest.id');
$expected = array(4, 2, 1);
$this->assertEqual($result, $expected);
} | testNodeObjectFind method
@access public
@return void | testNodeObjectFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function testNodeAliasParenting() {
$Aco = new DbAcoTest();
$db =& ConnectionManager::getDataSource('test_suite');
$db->truncate($Aco);
$db->_queriesLog = array();
$Aco->create(array('model' => null, 'foreign_key' => null, 'parent_id' => null, 'alias' => 'Application'));
$Aco->save();
$Aco->create(array('model' => null, 'foreign_key' => null, 'parent_id' => $Aco->id, 'alias' => 'Pages'));
$Aco->save();
$result = $Aco->find('all');
$expected = array(
array('DbAcoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'Application', 'lft' => '1', 'rght' => '4'), 'DbAroTest' => array()),
array('DbAcoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'Pages', 'lft' => '2', 'rght' => '3', ), 'DbAroTest' => array())
);
$this->assertEqual($result, $expected);
} | testNodeAliasParenting method
@access public
@return void | testNodeAliasParenting | php | Datawalke/Coordino | cake/tests/cases/libs/model/db_acl.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/db_acl.test.php | MIT |
function start() {
parent::start();
$this->debug = Configure::read('debug');
Configure::write('debug', 2);
} | start method
@access public
@return void | start | php | Datawalke/Coordino | cake/tests/cases/libs/model/model.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model.test.php | MIT |
function end() {
parent::end();
Configure::write('debug', $this->debug);
} | end method
@access public
@return void | end | php | Datawalke/Coordino | cake/tests/cases/libs/model/model.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model.test.php | MIT |
function validateNumber($value, $options) {
$options = array_merge(array('min' => 0, 'max' => 100), $options);
$valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']);
return $valid;
} | validateNumber method
@param mixed $value
@param mixed $options
@access public
@return void | validateNumber | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function validateTitle($value) {
return (!empty($value) && strpos(low($value['title']), 'title-') === 0);
} | validateTitle method
@param mixed $value
@access public
@return void | validateTitle | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function beforeSave() {
return $this->beforeSaveReturn;
} | beforeSave method
@access public
@return void | beforeSave | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function titleDuplicate ($title) {
if ($title === 'My Article Title') {
return false;
}
return true;
} | titleDuplicate method
@param mixed $title
@access public
@return void | titleDuplicate | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function afterFind($results) {
$results[0]['Author']['test'] = 'working';
return $results;
} | afterFind method
@param mixed $results
@access public
@return void | afterFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function afterFind($results) {
foreach($results as $index => $result) {
$results[$index]['Author']['user'] .= ' (CakePHP)';
}
return $results;
} | afterFind method
@param mixed $results
@access public
@return void | afterFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function afterFind($results) {
return $results;
} | afterFind method
@param mixed $results
@access public
@return void | afterFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function customValidationMethod($data) {
return $data === 1;
} | customValidationMethod method
@param mixed $data
@access public
@return void | customValidationMethod | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function customValidatorWithParams($data, $validator, $or = true, $ignore_on_same = 'id') {
$this->validatorParams = get_defined_vars();
unset($this->validatorParams['this']);
return true;
} | Custom validator with parameters + default values
@access public
@return array | customValidatorWithParams | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function customValidatorWithMessage($data) {
return 'This field will *never* validate! Muhahaha!';
} | Custom validator with messaage
@access public
@return array | customValidatorWithMessage | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) {
$this->validatorParams = get_defined_vars();
unset($this->validatorParams['this']);
return true;
} | Test validation with many parameters
@return void | customValidatorWithSixParams | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function customValidationMethod($data) {
return $data === 1;
} | customValidationMethod method
@param mixed $data
@access public
@return void | customValidationMethod | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function schema() {
return array();
} | schema method
@access public
@return void | schema | php | Datawalke/Coordino | cake/tests/cases/libs/model/models.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/models.php | MIT |
function setup(&$model, $config = array()) {
parent::setup($model, $config);
if (isset($config['mangle'])) {
$config['mangle'] .= ' mangled';
}
$this->settings[$model->alias] = array_merge(array('beforeFind' => 'on', 'afterFind' => 'off'), $config);
} | setup method
@param mixed $model
@param array $config
@access public
@return void | setup | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function beforeFind(&$model, $query) {
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeFind']) || $settings['beforeFind'] == 'off') {
return parent::beforeFind($model, $query);
}
switch ($settings['beforeFind']) {
case 'on':
return false;
break;
case 'test':
return null;
break;
case 'modify':
$query['fields'] = array($model->alias . '.id', $model->alias . '.name', $model->alias . '.mytime');
$query['recursive'] = -1;
return $query;
break;
}
} | beforeFind method
@param mixed $model
@param mixed $query
@access public
@return void | beforeFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function afterFind(&$model, $results, $primary) {
$settings = $this->settings[$model->alias];
if (!isset($settings['afterFind']) || $settings['afterFind'] == 'off') {
return parent::afterFind($model, $results, $primary);
}
switch ($settings['afterFind']) {
case 'on':
return array();
break;
case 'test':
return true;
break;
case 'test2':
return null;
break;
case 'modify':
return Set::extract($results, "{n}.{$model->alias}");
break;
}
} | afterFind method
@param mixed $model
@param mixed $results
@param mixed $primary
@access public
@return void | afterFind | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function beforeSave(&$model) {
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeSave']) || $settings['beforeSave'] == 'off') {
return parent::beforeSave($model);
}
switch ($settings['beforeSave']) {
case 'on':
return false;
break;
case 'test':
return null;
break;
case 'modify':
$model->data[$model->alias]['name'] .= ' modified before';
return true;
break;
}
} | beforeSave method
@param mixed $model
@access public
@return void | beforeSave | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function afterSave(&$model, $created) {
$settings = $this->settings[$model->alias];
if (!isset($settings['afterSave']) || $settings['afterSave'] == 'off') {
return parent::afterSave($model, $created);
}
$string = 'modified after';
if ($created) {
$string .= ' on create';
}
switch ($settings['afterSave']) {
case 'on':
$model->data[$model->alias]['aftersave'] = $string;
break;
case 'test':
unset($model->data[$model->alias]['name']);
break;
case 'test2':
return false;
break;
case 'modify':
$model->data[$model->alias]['name'] .= ' ' . $string;
break;
}
} | afterSave method
@param mixed $model
@param mixed $created
@access public
@return void | afterSave | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function beforeValidate(&$model) {
$settings = $this->settings[$model->alias];
if (!isset($settings['validate']) || $settings['validate'] == 'off') {
return parent::beforeValidate($model);
}
switch ($settings['validate']) {
case 'on':
$model->invalidate('name');
return true;
break;
case 'test':
return null;
break;
case 'whitelist':
$this->_addToWhitelist($model, array('name'));
return true;
break;
case 'stop':
$model->invalidate('name');
return false;
break;
}
} | beforeValidate method
@param mixed $model
@access public
@return void | beforeValidate | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function beforeDelete(&$model, $cascade = true) {
$settings =& $this->settings[$model->alias];
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') {
return parent::beforeDelete($model, $cascade);
}
switch ($settings['beforeDelete']) {
case 'on':
return false;
break;
case 'test':
return null;
break;
case 'test2':
echo 'beforeDelete success';
if ($cascade) {
echo ' (cascading) ';
}
break;
}
} | beforeDelete method
@param mixed $model
@param bool $cascade
@access public
@return void | beforeDelete | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function afterDelete(&$model) {
$settings =& $this->settings[$model->alias];
if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') {
return parent::afterDelete($model);
}
switch ($settings['afterDelete']) {
case 'on':
echo 'afterDelete success';
break;
}
} | afterDelete method
@param mixed $model
@access public
@return void | afterDelete | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function onError(&$model) {
$settings = $this->settings[$model->alias];
if (!isset($settings['onError']) || $settings['onError'] == 'off') {
return parent::onError($model, $cascade);
}
echo "onError trigger success";
} | onError method
@param mixed $model
@access public
@return void | onError | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function beforeTest(&$model) {
$model->beforeTestResult[] = strtolower(get_class($this));
return strtolower(get_class($this));
} | beforeTest method
@param mixed $model
@access public
@return void | beforeTest | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testMethod(&$model, $param = true) {
if ($param === true) {
return 'working';
}
} | testMethod method
@param mixed $model
@param bool $param
@access public
@return void | testMethod | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testData(&$model) {
if (!isset($model->data['Apple']['field'])) {
return false;
}
$model->data['Apple']['field_2'] = true;
return true;
} | testData method
@param mixed $model
@access public
@return void | testData | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function validateField(&$model, $field) {
return current($field) === 'Orange';
} | validateField method
@param mixed $model
@param mixed $field
@access public
@return void | validateField | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function speakEnglish(&$model, $method, $query) {
$method = preg_replace('/look for\s+/', 'Item.name = \'', $method);
$query = preg_replace('/^in\s+/', 'Location.name = \'', $query);
return $method . '\' AND ' . $query . '\'';
} | speakEnglish method
@param mixed $model
@param mixed $method
@param mixed $query
@access public
@return void | speakEnglish | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorBinding() {
$Apple = new Apple();
$this->assertIdentical($Apple->Behaviors->attached(), array());
$Apple->Behaviors->attach('Test', array('key' => 'value'));
$this->assertIdentical($Apple->Behaviors->attached(), array('Test'));
$this->assertEqual(strtolower(get_class($Apple->Behaviors->Test)), 'testbehavior');
$expected = array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value');
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
$this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple'));
$this->assertIdentical($Apple->Sample->Behaviors->attached(), array());
$Apple->Sample->Behaviors->attach('Test', array('key2' => 'value2'));
$this->assertIdentical($Apple->Sample->Behaviors->attached(), array('Test'));
$this->assertEqual($Apple->Sample->Behaviors->Test->settings['Sample'], array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'));
$this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple', 'Sample'));
$this->assertIdentical(
$Apple->Sample->Behaviors->Test->settings,
$Apple->Behaviors->Test->settings
);
$this->assertNotIdentical($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$Apple->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
$Apple->Sample->Behaviors->attach('Test', array('key' => 'value', 'key3' => 'value3', 'beforeFind' => 'off'));
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], array('beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'value', 'key2' => 'value2', 'key3' => 'value3'));
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$this->assertFalse(isset($Apple->Child->Behaviors->Test));
$Apple->Child->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
$this->assertEqual($Apple->Child->Behaviors->Test->settings['Child'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$this->assertFalse(isset($Apple->Parent->Behaviors->Test));
$Apple->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
$this->assertEqual($Apple->Parent->Behaviors->Test->settings['Parent'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$Apple->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'beforeFind' => 'off'));
$this->assertNotEqual($Apple->Parent->Behaviors->Test->settings['Parent'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value'));
$expected = array(
'beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value',
'key2' => 'value2', 'key3' => 'value3'
);
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
$current = $Apple->Behaviors->Test->settings['Apple'];
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
$Apple->Behaviors->attach('Test');
$expected = array_merge($current, array('mangle' => 'trigger mangled mangled'));
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
} | testBehaviorBinding method
@access public
@return void | testBehaviorBinding | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testDetachWithPluginNames() {
$Apple = new Apple();
$Apple->Behaviors->attach('Plugin.Test');
$this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
$this->assertEqual($Apple->Behaviors->attached(), array('Test'));
$Apple->Behaviors->detach('Plugin.Test');
$this->assertEqual($Apple->Behaviors->attached(), array());
$Apple->Behaviors->attach('Plugin.Test');
$this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
$this->assertEqual($Apple->Behaviors->attached(), array('Test'));
$Apple->Behaviors->detach('Test');
$this->assertEqual($Apple->Behaviors->attached(), array());
} | test that attach()/detach() works with plugin.banana
@return void | testDetachWithPluginNames | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testInvalidBehaviorCausingCakeError() {
$Apple =& new Apple();
$Apple->Behaviors =& new MockModelBehaviorCollection();
$Apple->Behaviors->expectOnce('cakeError');
$Apple->Behaviors->expectAt(0, 'cakeError', array('missingBehaviorFile', '*'));
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
} | test that attaching a non existant Behavior triggers a cake error.
@return void | testInvalidBehaviorCausingCakeError | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorToggling() {
$Apple = new Apple();
$this->assertIdentical($Apple->Behaviors->enabled(), array());
$Apple->Behaviors->init('Apple', array('Test' => array('key' => 'value')));
$this->assertIdentical($Apple->Behaviors->enabled(), array('Test'));
$Apple->Behaviors->disable('Test');
$this->assertIdentical($Apple->Behaviors->attached(), array('Test'));
$this->assertIdentical($Apple->Behaviors->enabled(), array());
$Apple->Sample->Behaviors->attach('Test');
$this->assertIdentical($Apple->Sample->Behaviors->enabled('Test'), true);
$this->assertIdentical($Apple->Behaviors->enabled(), array());
$Apple->Behaviors->enable('Test');
$this->assertIdentical($Apple->Behaviors->attached('Test'), true);
$this->assertIdentical($Apple->Behaviors->enabled(), array('Test'));
$Apple->Behaviors->disable('Test');
$this->assertIdentical($Apple->Behaviors->enabled(), array());
$Apple->Behaviors->attach('Test', array('enabled' => true));
$this->assertIdentical($Apple->Behaviors->enabled(), array('Test'));
$Apple->Behaviors->attach('Test', array('enabled' => false));
$this->assertIdentical($Apple->Behaviors->enabled(), array());
$Apple->Behaviors->detach('Test');
$this->assertIdentical($Apple->Behaviors->enabled(), array());
} | testBehaviorToggling method
@access public
@return void | testBehaviorToggling | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorFindCallbacks() {
$Apple = new Apple();
$expected = $Apple->find('all');
$Apple->Behaviors->attach('Test');
$this->assertIdentical($Apple->find('all'), null);
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Behaviors->attach('Test', array('beforeFind' => 'test'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Behaviors->attach('Test', array('beforeFind' => 'modify'));
$expected2 = array(
array('Apple' => array('id' => '1', 'name' => 'Red Apple 1', 'mytime' => '22:57:17')),
array('Apple' => array('id' => '2', 'name' => 'Bright Red Apple', 'mytime' => '22:57:17')),
array('Apple' => array('id' => '3', 'name' => 'green blue', 'mytime' => '22:57:17'))
);
$result = $Apple->find('all', array('conditions' => array('Apple.id <' => '4')));
$this->assertEqual($result, $expected2);
$Apple->Behaviors->disable('Test');
$result = $Apple->find('all');
$this->assertEqual($result, $expected);
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'on'));
$this->assertIdentical($Apple->find('all'), array());
$Apple->Behaviors->attach('Test', array('afterFind' => 'off'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Behaviors->attach('Test', array('afterFind' => 'test'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Behaviors->attach('Test', array('afterFind' => 'test2'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Behaviors->attach('Test', array('afterFind' => 'modify'));
$expected = array(
array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'),
array('id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'),
array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'),
array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'),
array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'),
array('id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17')
);
$this->assertEqual($Apple->find('all'), $expected);
} | testBehaviorFindCallbacks method
@access public
@return void | testBehaviorFindCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorHasManyFindCallbacks() {
$Apple = new Apple();
$Apple->unbindModel(array('hasOne' => array('Sample'), 'belongsTo' => array('Parent')), false);
$expected = $Apple->find('all');
$Apple->unbindModel(array('hasMany' => array('Child')));
$wellBehaved = $Apple->find('all');
$Apple->Child->Behaviors->attach('Test', array('afterFind' => 'modify'));
$Apple->unbindModel(array('hasMany' => array('Child')));
$this->assertIdentical($Apple->find('all'), $wellBehaved);
$Apple->Child->Behaviors->attach('Test', array('before' => 'off'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Child->Behaviors->attach('Test', array('before' => 'test'));
$this->assertIdentical($Apple->find('all'), $expected);
$expected2 = array(
array(
'Apple' => array('id' => 1),
'Child' => array(
array('id' => 2,'name' => 'Bright Red Apple', 'mytime' => '22:57:17'))),
array(
'Apple' => array('id' => 2),
'Child' => array(
array('id' => 1, 'name' => 'Red Apple 1', 'mytime' => '22:57:17'),
array('id' => 3, 'name' => 'green blue', 'mytime' => '22:57:17'),
array('id' => 4, 'name' => 'Test Name', 'mytime' => '22:57:17'))),
array(
'Apple' => array('id' => 3),
'Child' => array())
);
$Apple->Child->Behaviors->attach('Test', array('before' => 'modify'));
$result = $Apple->find('all', array('fields' => array('Apple.id'), 'conditions' => array('Apple.id <' => '4')));
//$this->assertEqual($result, $expected2);
$Apple->Child->Behaviors->disable('Test');
$result = $Apple->find('all');
$this->assertEqual($result, $expected);
$Apple->Child->Behaviors->attach('Test', array('before' => 'off', 'after' => 'on'));
//$this->assertIdentical($Apple->find('all'), array());
$Apple->Child->Behaviors->attach('Test', array('after' => 'off'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Child->Behaviors->attach('Test', array('after' => 'test'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Child->Behaviors->attach('Test', array('after' => 'test2'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Child->Behaviors->attach('Test', array('after' => 'modify'));
$expected = array(
array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'),
array('id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'),
array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'),
array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'),
array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'),
array('id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17')
);
//$this->assertEqual($Apple->find('all'), $expected);
} | testBehaviorHasManyFindCallbacks method
@access public
@return void | testBehaviorHasManyFindCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorHasOneFindCallbacks() {
$Apple = new Apple();
$Apple->unbindModel(array('hasMany' => array('Child'), 'belongsTo' => array('Parent')), false);
$expected = $Apple->find('all');
$Apple->unbindModel(array('hasOne' => array('Sample')));
$wellBehaved = $Apple->find('all');
$Apple->Sample->Behaviors->attach('Test');
$Apple->unbindModel(array('hasOne' => array('Sample')));
$this->assertIdentical($Apple->find('all'), $wellBehaved);
$Apple->Sample->Behaviors->attach('Test', array('before' => 'off'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Sample->Behaviors->attach('Test', array('before' => 'test'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Sample->Behaviors->attach('Test', array('before' => 'modify'));
$expected2 = array(
array(
'Apple' => array('id' => 1),
'Child' => array(
array('id' => 2,'name' => 'Bright Red Apple', 'mytime' => '22:57:17'))),
array(
'Apple' => array('id' => 2),
'Child' => array(
array('id' => 1, 'name' => 'Red Apple 1', 'mytime' => '22:57:17'),
array('id' => 3, 'name' => 'green blue', 'mytime' => '22:57:17'),
array('id' => 4, 'name' => 'Test Name', 'mytime' => '22:57:17'))),
array(
'Apple' => array('id' => 3),
'Child' => array())
);
$result = $Apple->find('all', array('fields' => array('Apple.id'), 'conditions' => array('Apple.id <' => '4')));
//$this->assertEqual($result, $expected2);
$Apple->Sample->Behaviors->disable('Test');
$result = $Apple->find('all');
$this->assertEqual($result, $expected);
$Apple->Sample->Behaviors->attach('Test', array('before' => 'off', 'after' => 'on'));
//$this->assertIdentical($Apple->find('all'), array());
$Apple->Sample->Behaviors->attach('Test', array('after' => 'off'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Sample->Behaviors->attach('Test', array('after' => 'test'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Sample->Behaviors->attach('Test', array('after' => 'test2'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Sample->Behaviors->attach('Test', array('after' => 'modify'));
$expected = array(
array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'),
array('id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'),
array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'),
array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'),
array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'),
array('id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17')
);
//$this->assertEqual($Apple->find('all'), $expected);
} | testBehaviorHasOneFindCallbacks method
@access public
@return void | testBehaviorHasOneFindCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorBelongsToFindCallbacks() {
$Apple = new Apple();
$Apple->unbindModel(array('hasMany' => array('Child'), 'hasOne' => array('Sample')), false);
$expected = $Apple->find('all');
$Apple->unbindModel(array('belongsTo' => array('Parent')));
$wellBehaved = $Apple->find('all');
$Apple->Parent->Behaviors->attach('Test');
$Apple->unbindModel(array('belongsTo' => array('Parent')));
$this->assertIdentical($Apple->find('all'), $wellBehaved);
$Apple->Parent->Behaviors->attach('Test', array('before' => 'off'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Parent->Behaviors->attach('Test', array('before' => 'test'));
$this->assertIdentical($Apple->find('all'), $expected);
$Apple->Parent->Behaviors->attach('Test', array('before' => 'modify'));
$expected2 = array(
array(
'Apple' => array('id' => 1),
'Parent' => array('id' => 2,'name' => 'Bright Red Apple', 'mytime' => '22:57:17')),
array(
'Apple' => array('id' => 2),
'Parent' => array('id' => 1, 'name' => 'Red Apple 1', 'mytime' => '22:57:17')),
array(
'Apple' => array('id' => 3),
'Parent' => array('id' => 2,'name' => 'Bright Red Apple', 'mytime' => '22:57:17'))
);
$result = $Apple->find('all', array(
'fields' => array('Apple.id', 'Parent.id', 'Parent.name', 'Parent.mytime'),
'conditions' => array('Apple.id <' => '4')
));
$this->assertEqual($result, $expected2);
$Apple->Parent->Behaviors->disable('Test');
$result = $Apple->find('all');
$this->assertEqual($result, $expected);
$Apple->Parent->Behaviors->attach('Test', array('after' => 'off'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test2'));
$this->assertEqual($Apple->find('all'), $expected);
$Apple->Parent->Behaviors->attach('Test', array('after' => 'modify'));
$expected = array(
array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'),
array('id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'),
array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'),
array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'),
array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'),
array('id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17')
);
//$this->assertEqual($Apple->find('all'), $expected);
} | testBehaviorBelongsToFindCallbacks method
@access public
@return void | testBehaviorBelongsToFindCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorSaveCallbacks() {
$Sample = new Sample();
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
$Sample->create();
$this->assertIdentical($Sample->save($record), false);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
$expected = Set::insert($record, 'Sample.name', 'sample99 modified before');
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->disable('Test');
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
$expected = Set::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
$Sample->recursive = -1;
$record2 = $Sample->read(null, 1);
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
$expected = Set::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
$expected = Set::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
} | testBehaviorSaveCallbacks method
@access public
@return void | testBehaviorSaveCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorDeleteCallbacks() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'beforeDelete' => 'off'));
$this->assertIdentical($Apple->delete(6), true);
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'on'));
$this->assertIdentical($Apple->delete(4), false);
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'test2'));
if (ob_start()) {
$results = $Apple->delete(4);
$this->assertIdentical(trim(ob_get_clean()), 'beforeDelete success (cascading)');
$this->assertIdentical($results, true);
}
if (ob_start()) {
$results = $Apple->delete(3, false);
$this->assertIdentical(trim(ob_get_clean()), 'beforeDelete success');
$this->assertIdentical($results, true);
}
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'off', 'afterDelete' => 'on'));
if (ob_start()) {
$results = $Apple->delete(2, false);
$this->assertIdentical(trim(ob_get_clean()), 'afterDelete success');
$this->assertIdentical($results, true);
}
} | testBehaviorDeleteCallbacks method
@access public
@return void | testBehaviorDeleteCallbacks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorOnErrorCallback() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'onError' => 'on'));
if (ob_start()) {
$Apple->Behaviors->Test->onError($Apple);
$this->assertIdentical(trim(ob_get_clean()), 'onError trigger success');
}
if (ob_start()) {
$Apple->delete(99);
//$this->assertIdentical(trim(ob_get_clean()), 'onError trigger success');
}
} | testBehaviorOnErrorCallback method
@access public
@return void | testBehaviorOnErrorCallback | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorValidateCallback() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test');
$this->assertIdentical($Apple->validates(), true);
$Apple->Behaviors->attach('Test', array('validate' => 'on'));
$this->assertIdentical($Apple->validates(), false);
$this->assertIdentical($Apple->validationErrors, array('name' => true));
$Apple->Behaviors->attach('Test', array('validate' => 'stop'));
$this->assertIdentical($Apple->validates(), false);
$this->assertIdentical($Apple->validationErrors, array('name' => true));
$Apple->Behaviors->attach('Test', array('validate' => 'whitelist'));
$Apple->validates();
$this->assertIdentical($Apple->whitelist, array());
$Apple->whitelist = array('unknown');
$Apple->validates();
$this->assertIdentical($Apple->whitelist, array('unknown', 'name'));
} | testBehaviorValidateCallback method
@access public
@return void | testBehaviorValidateCallback | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorValidateMethods() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test');
$Apple->validate['color'] = 'validateField';
$result = $Apple->save(array('name' => 'Genetically Modified Apple', 'color' => 'Orange'));
$this->assertEqual(array_keys($result['Apple']), array('name', 'color', 'modified', 'created'));
$Apple->create();
$result = $Apple->save(array('name' => 'Regular Apple', 'color' => 'Red'));
$this->assertFalse($result);
} | testBehaviorValidateMethods method
@access public
@return void | testBehaviorValidateMethods | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorMethodDispatching() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test');
$expected = 'working';
$this->assertEqual($Apple->testMethod(), $expected);
$this->assertEqual($Apple->Behaviors->dispatchMethod($Apple, 'testMethod'), $expected);
$result = $Apple->Behaviors->dispatchMethod($Apple, 'wtf');
$this->assertEqual($result, array('unhandled'));
$result = $Apple->{'look for the remote'}('in the couch');
$expected = "Item.name = 'the remote' AND Location.name = 'the couch'";
$this->assertEqual($result, $expected);
} | testBehaviorMethodDispatching method
@access public
@return void | testBehaviorMethodDispatching | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorMethodDispatchingWithData() {
$Apple = new Apple();
$Apple->Behaviors->attach('Test');
$Apple->set('field', 'value');
$this->assertTrue($Apple->testData());
$this->assertTrue($Apple->data['Apple']['field_2']);
$this->assertTrue($Apple->testData('one', 'two', 'three', 'four', 'five', 'six'));
} | testBehaviorMethodDispatchingWithData method
@access public
@return void | testBehaviorMethodDispatchingWithData | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorTrigger() {
$Apple =& new Apple();
$Apple->Behaviors->attach('Test');
$Apple->Behaviors->attach('Test2');
$Apple->Behaviors->attach('Test3');
$Apple->beforeTestResult = array();
$Apple->Behaviors->trigger($Apple, 'beforeTest');
$expected = array('testbehavior', 'test2behavior', 'test3behavior');
$this->assertIdentical($Apple->beforeTestResult, $expected);
$Apple->beforeTestResult = array();
$Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => 'test2behavior'));
$expected = array('testbehavior', 'test2behavior');
$this->assertIdentical($Apple->beforeTestResult, $expected);
$Apple->beforeTestResult = array();
$Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => array('test2behavior', 'test3behavior')));
$expected = array('testbehavior', 'test2behavior');
$this->assertIdentical($Apple->beforeTestResult, $expected);
} | testBehaviorTrigger method
@access public
@return void | testBehaviorTrigger | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBindModelCallsInBehaviors() {
$this->loadFixtures('Article', 'Comment');
// hasMany
$Article = new Article();
$Article->unbindModel(array('hasMany' => array('Comment')));
$result = $Article->find('first');
$this->assertFalse(array_key_exists('Comment', $result));
$Article->Behaviors->attach('Test4');
$result = $Article->find('first');
$this->assertTrue(array_key_exists('Comment', $result));
// belongsTo
$Article->unbindModel(array('belongsTo' => array('User')));
$result = $Article->find('first');
$this->assertFalse(array_key_exists('User', $result));
$Article->Behaviors->attach('Test5');
$result = $Article->find('first');
$this->assertTrue(array_key_exists('User', $result));
// hasAndBelongsToMany
$Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
$result = $Article->find('first');
$this->assertFalse(array_key_exists('Tag', $result));
$Article->Behaviors->attach('Test6');
$result = $Article->find('first');
$this->assertTrue(array_key_exists('Comment', $result));
// hasOne
$Comment = new Comment();
$Comment->unbindModel(array('hasOne' => array('Attachment')));
$result = $Comment->find('first');
$this->assertFalse(array_key_exists('Attachment', $result));
$Comment->Behaviors->attach('Test7');
$result = $Comment->find('first');
$this->assertTrue(array_key_exists('Attachment', $result));
} | undocumented function
@return void
@access public | testBindModelCallsInBehaviors | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testBehaviorAttachAndDetach() {
$Sample =& new Sample();
$Sample->actsAs = array('Test3' => array('bar'), 'Test2' => array('foo', 'bar'));
$Sample->Behaviors->init($Sample->alias, $Sample->actsAs);
$Sample->Behaviors->attach('Test2');
$Sample->Behaviors->detach('Test3');
$Sample->Behaviors->trigger($Sample, 'beforeTest');
} | Test attach and detaching
@access public
@return void | testBehaviorAttachAndDetach | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_behavior.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_behavior.test.php | MIT |
function testDeleteHabtmReferenceWithConditions() {
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
$Portfolio =& new Portfolio();
$Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1);
$result = $Portfolio->find('first', array(
'conditions' => array('Portfolio.id' => 1)
));
$expected = array(
array(
'id' => 3,
'syfile_id' => 3,
'published' => 0,
'name' => 'Item 3',
'ItemsPortfolio' => array(
'id' => 3,
'item_id' => 3,
'portfolio_id' => 1
)),
array(
'id' => 4,
'syfile_id' => 4,
'published' => 0,
'name' => 'Item 4',
'ItemsPortfolio' => array(
'id' => 4,
'item_id' => 4,
'portfolio_id' => 1
)),
array(
'id' => 5,
'syfile_id' => 5,
'published' => 0,
'name' => 'Item 5',
'ItemsPortfolio' => array(
'id' => 5,
'item_id' => 5,
'portfolio_id' => 1
)));
$this->assertEqual($result['Item'], $expected);
$result = $Portfolio->ItemsPortfolio->find('all', array(
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
));
$expected = array(
array(
'ItemsPortfolio' => array(
'id' => 1,
'item_id' => 1,
'portfolio_id' => 1
)),
array(
'ItemsPortfolio' => array(
'id' => 3,
'item_id' => 3,
'portfolio_id' => 1
)),
array(
'ItemsPortfolio' => array(
'id' => 4,
'item_id' => 4,
'portfolio_id' => 1
)),
array(
'ItemsPortfolio' => array(
'id' => 5,
'item_id' => 5,
'portfolio_id' => 1
)));
$this->assertEqual($result, $expected);
$Portfolio->delete(1);
$result = $Portfolio->find('first', array(
'conditions' => array('Portfolio.id' => 1)
));
$this->assertFalse($result);
$result = $Portfolio->ItemsPortfolio->find('all', array(
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
));
$this->assertFalse($result);
} | testDeleteHabtmReferenceWithConditions method
@access public
@return void | testDeleteHabtmReferenceWithConditions | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteArticleBLinks() {
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
$TestModel =& new ArticleB();
$result = $TestModel->ArticlesTag->find('all');
$expected = array(
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')),
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')),
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
);
$this->assertEqual($result, $expected);
$TestModel->delete(1);
$result = $TestModel->ArticlesTag->find('all');
$expected = array(
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
);
$this->assertEqual($result, $expected);
} | testDeleteArticleBLinks method
@access public
@return void | testDeleteArticleBLinks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteDependentWithConditions() {
$this->loadFixtures('Cd','Book','OverallFavorite');
$Cd =& new Cd();
$Book =& new Book();
$OverallFavorite =& new OverallFavorite();
$Cd->delete(1);
$result = $OverallFavorite->find('all', array(
'fields' => array('model_type', 'model_id', 'priority')
));
$expected = array(
array(
'OverallFavorite' => array(
'model_type' => 'Book',
'model_id' => 1,
'priority' => 2
)));
$this->assertTrue(is_array($result));
$this->assertEqual($result, $expected);
$Book->delete(1);
$result = $OverallFavorite->find('all', array(
'fields' => array('model_type', 'model_id', 'priority')
));
$expected = array();
$this->assertTrue(is_array($result));
$this->assertEqual($result, $expected);
} | testDeleteDependentWithConditions method
@access public
@return void | testDeleteDependentWithConditions | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDelete() {
$this->loadFixtures('Article');
$TestModel =& new Article();
$result = $TestModel->delete(2);
$this->assertTrue($result);
$result = $TestModel->read(null, 2);
$this->assertFalse($result);
$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'title')
));
$expected = array(
array('Article' => array(
'id' => 1,
'title' => 'First Article'
)),
array('Article' => array(
'id' => 3,
'title' => 'Third Article'
)));
$this->assertEqual($result, $expected);
$result = $TestModel->delete(3);
$this->assertTrue($result);
$result = $TestModel->read(null, 3);
$this->assertFalse($result);
$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'title')
));
$expected = array(
array('Article' => array(
'id' => 1,
'title' => 'First Article'
)));
$this->assertEqual($result, $expected);
// make sure deleting a non-existent record doesn't break save()
// ticket #6293
$this->loadFixtures('Uuid');
$Uuid =& new Uuid();
$data = array(
'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$Uuid->delete('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
$Uuid->delete('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$result = $Uuid->find('all', array(
'conditions' => array('id' => $data),
'fields' => array('id'),
'order' => 'id'));
$expected = array(
array('Uuid' => array(
'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
array('Uuid' => array(
'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
array('Uuid' => array(
'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
$this->assertEqual($result, $expected);
} | testDel method
@access public
@return void | testDelete | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteUpdatingCounterCacheCorrectly() {
$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
$User =& new CounterCacheUser();
$User->Post->delete(3);
$result = $User->read(null, 301);
$this->assertEqual($result['User']['post_count'], 0);
$result = $User->read(null, 66);
$this->assertEqual($result['User']['post_count'], 2);
} | test that delete() updates the correct records counterCache() records.
@return void | testDeleteUpdatingCounterCacheCorrectly | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteAll() {
$this->loadFixtures('Article');
$TestModel =& new Article();
$data = array('Article' => array(
'user_id' => 2,
'id' => 4,
'title' => 'Fourth Article',
'published' => 'N'
));
$result = $TestModel->set($data) && $TestModel->save();
$this->assertTrue($result);
$data = array('Article' => array(
'user_id' => 2,
'id' => 5,
'title' => 'Fifth Article',
'published' => 'Y'
));
$result = $TestModel->set($data) && $TestModel->save();
$this->assertTrue($result);
$data = array('Article' => array(
'user_id' => 1,
'id' => 6,
'title' => 'Sixth Article',
'published' => 'N'
));
$result = $TestModel->set($data) && $TestModel->save();
$this->assertTrue($result);
$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
));
$expected = array(
array('Article' => array(
'id' => 1,
'user_id' => 1,
'title' => 'First Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 2,
'user_id' => 3,
'title' => 'Second Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 3,
'user_id' => 1,
'title' => 'Third Article',
'published' => 'Y')),
array('Article' => array(
'id' => 4,
'user_id' => 2,
'title' => 'Fourth Article',
'published' => 'N'
)),
array('Article' => array(
'id' => 5,
'user_id' => 2,
'title' => 'Fifth Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 6,
'user_id' => 1,
'title' => 'Sixth Article',
'published' => 'N'
)));
$this->assertEqual($result, $expected);
$result = $TestModel->deleteAll(array('Article.published' => 'N'));
$this->assertTrue($result);
$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
));
$expected = array(
array('Article' => array(
'id' => 1,
'user_id' => 1,
'title' => 'First Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 2,
'user_id' => 3,
'title' => 'Second Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 3,
'user_id' => 1,
'title' => 'Third Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 5,
'user_id' => 2,
'title' => 'Fifth Article',
'published' => 'Y'
)));
$this->assertEqual($result, $expected);
$data = array('Article.user_id' => array(2, 3));
$result = $TestModel->deleteAll($data, true, true);
$this->assertTrue($result);
$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
));
$expected = array(
array('Article' => array(
'id' => 1,
'user_id' => 1,
'title' => 'First Article',
'published' => 'Y'
)),
array('Article' => array(
'id' => 3,
'user_id' => 1,
'title' => 'Third Article',
'published' => 'Y'
)));
$this->assertEqual($result, $expected);
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
$this->expectError();
ob_start();
$result = $TestModel->deleteAll(array('Article.non_existent_field' => 999));
ob_get_clean();
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
} | testDeleteAll method
@access public
@return void | testDeleteAll | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testRecursiveDel() {
$this->loadFixtures('Article', 'Comment', 'Attachment');
$TestModel =& new Article();
$result = $TestModel->delete(2);
$this->assertTrue($result);
$TestModel->recursive = 2;
$result = $TestModel->read(null, 2);
$this->assertFalse($result);
$result = $TestModel->Comment->read(null, 5);
$this->assertFalse($result);
$result = $TestModel->Comment->read(null, 6);
$this->assertFalse($result);
$result = $TestModel->Comment->Attachment->read(null, 1);
$this->assertFalse($result);
$result = $TestModel->find('count');
$this->assertEqual($result, 2);
$result = $TestModel->Comment->find('count');
$this->assertEqual($result, 4);
$result = $TestModel->Comment->Attachment->find('count');
$this->assertEqual($result, 0);
} | testRecursiveDel method
@access public
@return void | testRecursiveDel | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDependentExclusiveDelete() {
$this->loadFixtures('Article', 'Comment');
$TestModel =& new Article10();
$result = $TestModel->find('all');
$this->assertEqual(count($result[0]['Comment']), 4);
$this->assertEqual(count($result[1]['Comment']), 2);
$this->assertEqual($TestModel->Comment->find('count'), 6);
$TestModel->delete(1);
$this->assertEqual($TestModel->Comment->find('count'), 2);
} | testDependentExclusiveDelete method
@access public
@return void | testDependentExclusiveDelete | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteLinks() {
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
$TestModel =& new Article();
$result = $TestModel->ArticlesTag->find('all');
$expected = array(
array('ArticlesTag' => array(
'article_id' => '1',
'tag_id' => '1'
)),
array('ArticlesTag' => array(
'article_id' => '1',
'tag_id' => '2'
)),
array('ArticlesTag' => array(
'article_id' => '2',
'tag_id' => '1'
)),
array('ArticlesTag' => array(
'article_id' => '2',
'tag_id' => '3'
)));
$this->assertEqual($result, $expected);
$TestModel->delete(1);
$result = $TestModel->ArticlesTag->find('all');
$expected = array(
array('ArticlesTag' => array(
'article_id' => '2',
'tag_id' => '1'
)),
array('ArticlesTag' => array(
'article_id' => '2',
'tag_id' => '3'
)));
$this->assertEqual($result, $expected);
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
} | testDeleteLinks method
@access public
@return void | testDeleteLinks | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteDependent() {
$this->loadFixtures('Bidding', 'BiddingMessage');
$Bidding = new Bidding();
$result = $Bidding->find('all');
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1'),
),
array(
'Bidding' => array('id' => 2, 'bid' => 'Two', 'name' => 'Bid 2'),
'BiddingMessage' => array('bidding' => 'Two', 'name' => 'Message 2'),
),
array(
'Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'),
'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3'),
),
array(
'Bidding' => array('id' => 4, 'bid' => 'Five', 'name' => 'Bid 5'),
'BiddingMessage' => array('bidding' => '', 'name' => ''),
),
);
$this->assertEqual($result, $expected);
$Bidding->delete(4, true);
$result = $Bidding->find('all');
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1'),
),
array(
'Bidding' => array('id' => 2, 'bid' => 'Two', 'name' => 'Bid 2'),
'BiddingMessage' => array('bidding' => 'Two', 'name' => 'Message 2'),
),
array(
'Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'),
'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3'),
),
);
$this->assertEqual($result, $expected);
$Bidding->delete(2, true);
$result = $Bidding->find('all');
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1'),
),
array(
'Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'),
'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3'),
),
);
$this->assertEqual($result, $expected);
$result = $Bidding->BiddingMessage->find('all', array('order' => array('BiddingMessage.name' => 'ASC')));
$expected = array(
array(
'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1'),
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
),
array(
'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3'),
'Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'),
),
array(
'BiddingMessage' => array('bidding' => 'Four', 'name' => 'Message 4'),
'Bidding' => array('id' => '', 'bid' => '', 'name' => ''),
),
);
$this->assertEqual($result, $expected);
} | testDeleteDependent method
@access public
@return void | testDeleteDependent | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteLinksWithMultipleHabtmAssociations() {
$this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC');
$JoinA =& new JoinA();
//create two new join records to expose the issue.
$JoinA->JoinAsJoinC->create(array(
'join_a_id' => 1,
'join_c_id' => 2,
));
$JoinA->JoinAsJoinC->save();
$JoinA->JoinAsJoinB->create(array(
'join_a_id' => 1,
'join_b_id' => 2,
));
$JoinA->JoinAsJoinB->save();
$result = $JoinA->delete(1);
$this->assertTrue($result, 'Delete failed %s');
$joinedBs = $JoinA->JoinAsJoinB->find('count', array(
'conditions' => array('JoinAsJoinB.join_a_id' => 1)
));
$this->assertEqual($joinedBs, 0, 'JoinA/JoinB link records left over. %s');
$joinedBs = $JoinA->JoinAsJoinC->find('count', array(
'conditions' => array('JoinAsJoinC.join_a_id' => 1)
));
$this->assertEqual($joinedBs, 0, 'JoinA/JoinC link records left over. %s');
} | test deleteLinks with Multiple habtm associations
@return void | testDeleteLinksWithMultipleHabtmAssociations | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
$ThePaper =& new ThePaper();
$ThePaper->id = 1;
$ThePaper->save(array('Monkey' => array(2, 3)));
$result = $ThePaper->findById(1);
$expected = array(
array(
'id' => '2',
'device_type_id' => '1',
'name' => 'Device 2',
'typ' => '1'
),
array(
'id' => '3',
'device_type_id' => '1',
'name' => 'Device 3',
'typ' => '2'
));
$this->assertEqual($result['Monkey'], $expected);
$ThePaper =& new ThePaper();
$ThePaper->id = 2;
$ThePaper->save(array('Monkey' => array(2, 3)));
$result = $ThePaper->findById(2);
$expected = array(
array(
'id' => '2',
'device_type_id' => '1',
'name' => 'Device 2',
'typ' => '1'
),
array(
'id' => '3',
'device_type_id' => '1',
'name' => 'Device 3',
'typ' => '2'
));
$this->assertEqual($result['Monkey'], $expected);
$ThePaper->delete(1);
$result = $ThePaper->findById(2);
$expected = array(
array(
'id' => '2',
'device_type_id' => '1',
'name' => 'Device 2',
'typ' => '1'
),
array(
'id' => '3',
'device_type_id' => '1',
'name' => 'Device 3',
'typ' => '2'
));
$this->assertEqual($result['Monkey'], $expected);
} | testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
@access public
@return void | testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testBeforeDeleteDeleteAbortion() {
$this->loadFixtures('Post');
$Model =& new CallbackPostTestModel();
$Model->beforeDeleteReturn = false;
$result = $Model->delete(1);
$this->assertFalse($result);
$exists = $Model->findById(1);
$this->assertTrue(is_array($exists));
} | test that beforeDelete returning false can abort deletion.
@return void | testBeforeDeleteDeleteAbortion | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testDeleteHabtmPostgresFailure() {
$this->loadFixtures('Article', 'Tag', 'ArticlesTag');
$Article =& ClassRegistry::init('Article');
$Article->hasAndBelongsToMany['Tag']['unique'] = true;
$Tag =& ClassRegistry::init('Tag');
$Tag->bindModel(array('hasAndBelongsToMany' => array(
'Article' => array(
'className' => 'Article',
'unique' => true
)
)), true);
// Article 1 should have Tag.1 and Tag.2
$before = $Article->find("all", array(
"conditions" => array("Article.id" => 1),
));
$this->assertEqual(count($before[0]['Tag']), 2, 'Tag count for Article.id = 1 is incorrect, should be 2 %s');
// From now on, Tag #1 is only associated with Post #1
$submitted_data = array(
"Tag" => array("id" => 1, 'tag' => 'tag1'),
"Article" => array(
"Article" => array(1)
)
);
$Tag->save($submitted_data);
// One more submission (The other way around) to make sure the reverse save looks good.
$submitted_data = array(
"Article" => array("id" => 2, 'title' => 'second article'),
"Tag" => array(
"Tag" => array(2, 3)
)
);
// ERROR:
// Postgresql: DELETE FROM "articles_tags" WHERE tag_id IN ('1', '3')
// MySQL: DELETE `ArticlesTag` FROM `articles_tags` AS `ArticlesTag` WHERE `ArticlesTag`.`article_id` = 2 AND `ArticlesTag`.`tag_id` IN (1, 3)
$Article->save($submitted_data);
// Want to make sure Article #1 has Tag #1 and Tag #2 still.
$after = $Article->find("all", array(
"conditions" => array("Article.id" => 1),
));
// Removing Article #2 from Tag #1 is all that should have happened.
$this->assertEqual(count($before[0]["Tag"]), count($after[0]["Tag"]));
} | test for a habtm deletion error that occurs in postgres but should not.
And should not occur in any dbo.
@return void | testDeleteHabtmPostgresFailure | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testBeforeDeleteWipingTable() {
$this->loadFixtures('Comment');
$Comment =& new BeforeDeleteComment();
// Delete 3 records.
$Comment->delete(4);
$result = $Comment->find('count');
$this->assertTrue($result > 1, 'Comments are all gone.');
$Comment->create(array(
'article_id' => 1,
'user_id' => 2,
'comment' => 'new record',
'published' => 'Y'
));
$Comment->save();
$Comment->delete(5);
$result = $Comment->find('count');
$this->assertTrue($result > 1, 'Comments are all gone.');
} | test that deleting records inside the beforeDelete doesn't truncate the table.
@return void | testBeforeDeleteWipingTable | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function testBeforeDeleteWipingTableWithDuplicateDelete() {
$this->loadFixtures('Comment');
$Comment =& new BeforeDeleteComment();
$Comment->delete(1);
$result = $Comment->find('count');
$this->assertTrue($result > 1, 'Comments are all gone.');
} | test that deleting the same record from the beforeDelete and the delete doesn't truncate the table.
@return void | testBeforeDeleteWipingTableWithDuplicateDelete | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_delete.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_delete.test.php | MIT |
function connect() {
return true;
} | Returns true to fake a database connection | connect | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testCacheSourcesDisabling() {
$this->db->cacheSources = true;
$TestModel = new JoinA();
$TestModel->cacheSources = false;
$TestModel->setSource('join_as');
$this->assertFalse($this->db->cacheSources);
$this->db->cacheSources = false;
$TestModel = new JoinA();
$TestModel->cacheSources = true;
$TestModel->setSource('join_as');
$this->assertFalse($this->db->cacheSources);
} | Tests that $cacheSources can only be disabled in the db using model settings, not enabled
@access public
@return void | testCacheSourcesDisabling | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testPkInHabtmLinkModel() {
//Test Nonconformant Models
$this->loadFixtures('Content', 'ContentAccount', 'Account');
$TestModel =& new Content();
$this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId');
//test conformant models with no PK in the join table
$this->loadFixtures('Article', 'Tag');
$TestModel2 =& new Article();
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
//test conformant models with PK in join table
$this->loadFixtures('Item', 'Portfolio', 'ItemsPortfolio');
$TestModel3 =& new Portfolio();
$this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id');
//test conformant models with PK in join table - join table contains extra field
$this->loadFixtures('JoinA', 'JoinB', 'JoinAB');
$TestModel4 =& new JoinA();
$this->assertEqual($TestModel4->JoinAsJoinB->primaryKey, 'id');
} | testPkInHabtmLinkModel method
@access public
@return void | testPkInHabtmLinkModel | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testDynamicBehaviorAttachment() {
$this->loadFixtures('Apple');
$TestModel =& new Apple();
$this->assertEqual($TestModel->Behaviors->attached(), array());
$TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field'));
$this->assertTrue(is_object($TestModel->Behaviors->Tree));
$this->assertEqual($TestModel->Behaviors->attached(), array('Tree'));
$expected = array(
'parent' => 'parent_id',
'left' => 'left_field',
'right' => 'right_field',
'scope' => '1 = 1',
'type' => 'nested',
'__parentChange' => false,
'recursive' => -1
);
$this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected);
$expected['enabled'] = false;
$TestModel->Behaviors->attach('Tree', array('enabled' => false));
$this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected);
$this->assertEqual($TestModel->Behaviors->attached(), array('Tree'));
$TestModel->Behaviors->detach('Tree');
$this->assertEqual($TestModel->Behaviors->attached(), array());
$this->assertFalse(isset($TestModel->Behaviors->Tree));
} | testDynamicBehaviorAttachment method
@access public
@return void | testDynamicBehaviorAttachment | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testFindWithJoinsOption() {
$this->loadFixtures('Article', 'User');
$TestUser =& new User();
$options = array (
'fields' => array(
'user',
'Article.published',
),
'joins' => array (
array (
'table' => 'articles',
'alias' => 'Article',
'type' => 'LEFT',
'conditions' => array(
'User.id = Article.user_id',
),
),
),
'group' => array('User.user'),
'recursive' => -1,
);
$result = $TestUser->find('all', $options);
$expected = array(
array('User' => array('user' => 'garrett'), 'Article' => array('published' => '')),
array('User' => array('user' => 'larry'), 'Article' => array('published' => 'Y')),
array('User' => array('user' => 'mariano'), 'Article' => array('published' => 'Y')),
array('User' => array('user' => 'nate'), 'Article' => array('published' => ''))
);
$this->assertEqual($result, $expected);
} | testFindWithJoinsOption method
@access public
@return void | testFindWithJoinsOption | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testCrossDatabaseJoins() {
$config = new DATABASE_CONFIG();
$skip = $this->skipIf(
!isset($config->test) || !isset($config->test2),
'%s Primary and secondary test databases not configured, skipping cross-database '
.'join tests.'
.' To run these tests, you must define $test and $test2 in your database configuration.'
);
if ($skip) {
return;
}
$this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment');
$TestModel =& new Article();
$expected = array(
array(
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
),
'User' => array(
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array(
array(
'id' => '1',
'article_id' => '1',
'user_id' => '2',
'comment' => 'First Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:45:23',
'updated' => '2007-03-18 10:47:31'
),
array(
'id' => '2',
'article_id' => '1',
'user_id' => '4',
'comment' => 'Second Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:47:23',
'updated' => '2007-03-18 10:49:31'
),
array(
'id' => '3',
'article_id' => '1',
'user_id' => '1',
'comment' => 'Third Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:49:23',
'updated' => '2007-03-18 10:51:31'
),
array(
'id' => '4',
'article_id' => '1',
'user_id' => '1',
'comment' => 'Fourth Comment for First Article',
'published' => 'N',
'created' => '2007-03-18 10:51:23',
'updated' => '2007-03-18 10:53:31'
)),
'Tag' => array(
array(
'id' => '1',
'tag' => 'tag1',
'created' => '2007-03-18 12:22:23',
'updated' => '2007-03-18 12:24:31'
),
array(
'id' => '2',
'tag' => 'tag2',
'created' => '2007-03-18 12:24:23',
'updated' => '2007-03-18 12:26:31'
))),
array(
'Article' => array(
'id' => '2',
'user_id' => '3',
'title' => 'Second Article',
'body' => 'Second Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:41:23',
'updated' => '2007-03-18 10:43:31'
),
'User' => array(
'id' => '3',
'user' => 'larry',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:20:23',
'updated' => '2007-03-17 01:22:31'
),
'Comment' => array(
array(
'id' => '5',
'article_id' => '2',
'user_id' => '1',
'comment' => 'First Comment for Second Article',
'published' => 'Y',
'created' => '2007-03-18 10:53:23',
'updated' => '2007-03-18 10:55:31'
),
array(
'id' => '6',
'article_id' => '2',
'user_id' => '2',
'comment' => 'Second Comment for Second Article',
'published' => 'Y',
'created' => '2007-03-18 10:55:23',
'updated' => '2007-03-18 10:57:31'
)),
'Tag' => array(
array(
'id' => '1',
'tag' => 'tag1',
'created' => '2007-03-18 12:22:23',
'updated' => '2007-03-18 12:24:31'
),
array(
'id' => '3',
'tag' => 'tag3',
'created' => '2007-03-18 12:26:23',
'updated' => '2007-03-18 12:28:31'
))),
array(
'Article' => array(
'id' => '3',
'user_id' => '1',
'title' => 'Third Article',
'body' => 'Third Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:43:23',
'updated' => '2007-03-18 10:45:31'
),
'User' => array(
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array(),
'Tag' => array()
));
$this->assertEqual($TestModel->find('all'), $expected);
$db2 =& ConnectionManager::getDataSource('test2');
foreach (array('User', 'Comment') as $class) {
$this->_fixtures[$this->_fixtureClassMap[$class]]->create($db2);
$this->_fixtures[$this->_fixtureClassMap[$class]]->insert($db2);
$this->db->truncate(Inflector::pluralize(Inflector::underscore($class)));
}
$this->assertEqual($TestModel->User->find('all'), array());
$this->assertEqual($TestModel->Comment->find('all'), array());
$this->assertEqual($TestModel->find('count'), 3);
$TestModel->User->setDataSource('test2');
$TestModel->Comment->setDataSource('test2');
foreach ($expected as $key => $value) {
unset($value['Comment'], $value['Tag']);
$expected[$key] = $value;
}
$TestModel->recursive = 0;
$result = $TestModel->find('all');
$this->assertEqual($result, $expected);
foreach ($expected as $key => $value) {
unset($value['Comment'], $value['Tag']);
$expected[$key] = $value;
}
$TestModel->recursive = 0;
$result = $TestModel->find('all');
$this->assertEqual($result, $expected);
$result = Set::extract($TestModel->User->find('all'), '{n}.User.id');
$this->assertEqual($result, array('1', '2', '3', '4'));
$this->assertEqual($TestModel->find('all'), $expected);
$TestModel->Comment->unbindModel(array('hasOne' => array('Attachment')));
$expected = array(
array(
'Comment' => array(
'id' => '1',
'article_id' => '1',
'user_id' => '2',
'comment' => 'First Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:45:23',
'updated' => '2007-03-18 10:47:31'
),
'User' => array(
'id' => '2',
'user' => 'nate',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:18:23',
'updated' => '2007-03-17 01:20:31'
),
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)),
array(
'Comment' => array(
'id' => '2',
'article_id' => '1',
'user_id' => '4',
'comment' => 'Second Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:47:23',
'updated' => '2007-03-18 10:49:31'
),
'User' => array(
'id' => '4',
'user' => 'garrett',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:22:23',
'updated' => '2007-03-17 01:24:31'
),
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)),
array(
'Comment' => array(
'id' => '3',
'article_id' => '1',
'user_id' => '1',
'comment' => 'Third Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:49:23',
'updated' => '2007-03-18 10:51:31'
),
'User' => array(
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)),
array(
'Comment' => array(
'id' => '4',
'article_id' => '1',
'user_id' => '1',
'comment' => 'Fourth Comment for First Article',
'published' => 'N',
'created' => '2007-03-18 10:51:23',
'updated' => '2007-03-18 10:53:31'
),
'User' => array(
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)),
array(
'Comment' => array(
'id' => '5',
'article_id' => '2',
'user_id' => '1',
'comment' => 'First Comment for Second Article',
'published' => 'Y',
'created' => '2007-03-18 10:53:23',
'updated' => '2007-03-18 10:55:31'
),
'User' => array(
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Article' => array(
'id' => '2',
'user_id' => '3',
'title' => 'Second Article',
'body' => 'Second Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:41:23',
'updated' => '2007-03-18 10:43:31'
)),
array(
'Comment' => array(
'id' => '6',
'article_id' => '2',
'user_id' => '2',
'comment' => 'Second Comment for Second Article',
'published' => 'Y',
'created' => '2007-03-18 10:55:23',
'updated' => '2007-03-18 10:57:31'
),
'User' => array(
'id' => '2',
'user' => 'nate',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:18:23',
'updated' => '2007-03-17 01:20:31'
),
'Article' => array(
'id' => '2',
'user_id' => '3',
'title' => 'Second Article',
'body' => 'Second Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:41:23',
'updated' => '2007-03-18 10:43:31'
)));
$this->assertEqual($TestModel->Comment->find('all'), $expected);
foreach (array('User', 'Comment') as $class) {
$this->_fixtures[$this->_fixtureClassMap[$class]]->drop($db2);
}
} | Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG
NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
or one connection will step on the other. | testCrossDatabaseJoins | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testDisplayField() {
$this->loadFixtures('Post', 'Comment', 'Person');
$Post = new Post();
$Comment = new Comment();
$Person = new Person();
$this->assertEqual($Post->displayField, 'title');
$this->assertEqual($Person->displayField, 'name');
$this->assertEqual($Comment->displayField, 'id');
} | testDisplayField method
@access public
@return void | testDisplayField | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testSchema() {
$Post = new Post();
$result = $Post->schema();
$columns = array('id', 'author_id', 'title', 'body', 'published', 'created', 'updated');
$this->assertEqual(array_keys($result), $columns);
$types = array('integer', 'integer', 'string', 'text', 'string', 'datetime', 'datetime');
$this->assertEqual(Set::extract(array_values($result), '{n}.type'), $types);
$result = $Post->schema('body');
$this->assertEqual($result['type'], 'text');
$this->assertNull($Post->schema('foo'));
$this->assertEqual($Post->getColumnTypes(), array_combine($columns, $types));
} | testSchema method
@access public
@return void | testSchema | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testDeconstructFieldsTime() {
$this->loadFixtures('Apple');
$TestModel =& new Apple();
$data = array();
$data['Apple']['mytime']['hour'] = '';
$data['Apple']['mytime']['min'] = '';
$data['Apple']['mytime']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['mytime']['hour'] = '';
$data['Apple']['mytime']['min'] = '';
$data['Apple']['mytime']['meridan'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> ''));
$this->assertEqual($TestModel->data, $expected, 'Empty values are not returning properly. %s');
$data = array();
$data['Apple']['mytime']['hour'] = '12';
$data['Apple']['mytime']['min'] = '0';
$data['Apple']['mytime']['meridian'] = 'am';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> '00:00:00'));
$this->assertEqual($TestModel->data, $expected, 'Midnight is not returning proper values. %s');
$data = array();
$data['Apple']['mytime']['hour'] = '00';
$data['Apple']['mytime']['min'] = '00';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> '00:00:00'));
$this->assertEqual($TestModel->data, $expected, 'Midnight is not returning proper values. %s');
$data = array();
$data['Apple']['mytime']['hour'] = '03';
$data['Apple']['mytime']['min'] = '04';
$data['Apple']['mytime']['sec'] = '04';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> '03:04:04'));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['mytime']['hour'] = '3';
$data['Apple']['mytime']['min'] = '4';
$data['Apple']['mytime']['sec'] = '4';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple' => array('mytime'=> '03:04:04'));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['mytime']['hour'] = '03';
$data['Apple']['mytime']['min'] = '4';
$data['Apple']['mytime']['sec'] = '4';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> '03:04:04'));
$this->assertEqual($TestModel->data, $expected);
$db = ConnectionManager::getDataSource('test_suite');
$data = array();
$data['Apple']['mytime'] = $db->expression('NOW()');
$TestModel->data = null;
$TestModel->set($data);
$this->assertEqual($TestModel->data, $data);
} | test deconstruct() with time fields.
@return void | testDeconstructFieldsTime | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testDeconstructFieldsDateTime() {
$this->loadFixtures('Apple');
$TestModel =& new Apple();
//test null/empty values first
$data['Apple']['created']['year'] = '';
$data['Apple']['created']['month'] = '';
$data['Apple']['created']['day'] = '';
$data['Apple']['created']['hour'] = '';
$data['Apple']['created']['min'] = '';
$data['Apple']['created']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['date']['year'] = '';
$data['Apple']['date']['month'] = '';
$data['Apple']['date']['day'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('date'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '08';
$data['Apple']['created']['day'] = '20';
$data['Apple']['created']['hour'] = '';
$data['Apple']['created']['min'] = '';
$data['Apple']['created']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> '2007-08-20 00:00:00'));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '08';
$data['Apple']['created']['day'] = '20';
$data['Apple']['created']['hour'] = '10';
$data['Apple']['created']['min'] = '12';
$data['Apple']['created']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> '2007-08-20 10:12:00'));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '';
$data['Apple']['created']['day'] = '12';
$data['Apple']['created']['hour'] = '20';
$data['Apple']['created']['min'] = '';
$data['Apple']['created']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['hour'] = '20';
$data['Apple']['created']['min'] = '33';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['hour'] = '20';
$data['Apple']['created']['min'] = '33';
$data['Apple']['created']['sec'] = '33';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['hour'] = '13';
$data['Apple']['created']['min'] = '00';
$data['Apple']['date']['year'] = '2006';
$data['Apple']['date']['month'] = '12';
$data['Apple']['date']['day'] = '25';
$TestModel->data = null;
$TestModel->set($data);
$expected = array(
'Apple'=> array(
'created'=> '',
'date'=> '2006-12-25'
));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '08';
$data['Apple']['created']['day'] = '20';
$data['Apple']['created']['hour'] = '10';
$data['Apple']['created']['min'] = '12';
$data['Apple']['created']['sec'] = '09';
$data['Apple']['date']['year'] = '2006';
$data['Apple']['date']['month'] = '12';
$data['Apple']['date']['day'] = '25';
$TestModel->data = null;
$TestModel->set($data);
$expected = array(
'Apple'=> array(
'created'=> '2007-08-20 10:12:09',
'date'=> '2006-12-25'
));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '--';
$data['Apple']['created']['month'] = '--';
$data['Apple']['created']['day'] = '--';
$data['Apple']['created']['hour'] = '--';
$data['Apple']['created']['min'] = '--';
$data['Apple']['created']['sec'] = '--';
$data['Apple']['date']['year'] = '--';
$data['Apple']['date']['month'] = '--';
$data['Apple']['date']['day'] = '--';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> '', 'date'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '--';
$data['Apple']['created']['day'] = '20';
$data['Apple']['created']['hour'] = '10';
$data['Apple']['created']['min'] = '12';
$data['Apple']['created']['sec'] = '09';
$data['Apple']['date']['year'] = '2006';
$data['Apple']['date']['month'] = '12';
$data['Apple']['date']['day'] = '25';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('created'=> '', 'date'=> '2006-12-25'));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['date']['year'] = '2006';
$data['Apple']['date']['month'] = '12';
$data['Apple']['date']['day'] = '25';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('date'=> '2006-12-25'));
$this->assertEqual($TestModel->data, $expected);
$db = ConnectionManager::getDataSource('test_suite');
$data = array();
$data['Apple']['modified'] = $db->expression('NOW()');
$TestModel->data = null;
$TestModel->set($data);
$this->assertEqual($TestModel->data, $data);
} | testDeconstructFields with datetime, timestamp, and date fields
@access public
@return void | testDeconstructFieldsDateTime | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testTablePrefixSwitching() {
ConnectionManager::create('database1',
array_merge($this->db->config, array('prefix' => 'aaa_')
));
ConnectionManager::create('database2',
array_merge($this->db->config, array('prefix' => 'bbb_')
));
$db1 = ConnectionManager::getDataSource('database1');
$db2 = ConnectionManager::getDataSource('database2');
$TestModel = new Apple();
$TestModel->setDataSource('database1');
$this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples');
$this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples');
$TestModel->setDataSource('database2');
$this->assertEqual($this->db->fullTableName($TestModel, false), 'bbb_apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'bbb_apples');
$this->assertEqual($db2->fullTableName($TestModel, false), 'bbb_apples');
$TestModel = new Apple();
$TestModel->tablePrefix = 'custom_';
$this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples');
$TestModel->setDataSource('database1');
$this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'custom_apples');
$TestModel = new Apple();
$TestModel->setDataSource('database1');
$this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples');
$TestModel->tablePrefix = '';
$TestModel->setDataSource('database2');
$this->assertEqual($db2->fullTableName($TestModel, false), 'apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'apples');
$TestModel->tablePrefix = null;
$TestModel->setDataSource('database1');
$this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples');
$TestModel->tablePrefix = false;
$TestModel->setDataSource('database2');
$this->assertEqual($db2->fullTableName($TestModel, false), 'apples');
$this->assertEqual($db1->fullTableName($TestModel, false), 'apples');
} | testTablePrefixSwitching method
@access public
@return void | testTablePrefixSwitching | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testInvalidAssociation() {
$TestModel =& new ValidationTest1();
$this->assertNull($TestModel->getAssociated('Foo'));
} | Tests validation parameter order in custom validation methods
@access public
@return void | testInvalidAssociation | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testLoadModelSecondIteration() {
$model = new ModelA();
$this->assertIsA($model,'ModelA');
$this->assertIsA($model->ModelB, 'ModelB');
$this->assertIsA($model->ModelB->ModelD, 'ModelD');
$this->assertIsA($model->ModelC, 'ModelC');
$this->assertIsA($model->ModelC->ModelD, 'ModelD');
} | testLoadModelSecondIteration method
@access public
@return void | testLoadModelSecondIteration | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testResetOfExistsOnCreate() {
$this->loadFixtures('Article');
$Article =& new Article();
$Article->id = 1;
$Article->saveField('title', 'Reset me');
$Article->delete();
$Article->id = 1;
$this->assertFalse($Article->exists());
$Article->create();
$this->assertFalse($Article->exists());
$Article->id = 2;
$Article->saveField('title', 'Staying alive');
$result = $Article->read(null, 2);
$this->assertEqual($result['Article']['title'], 'Staying alive');
} | ensure that exists() does not persist between method calls reset on create
@return void | testResetOfExistsOnCreate | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testPluginAssociations() {
$this->loadFixtures('TestPluginArticle', 'User', 'TestPluginComment');
$TestModel =& new TestPluginArticle();
$result = $TestModel->find('all');
$expected = array(
array(
'TestPluginArticle' => array(
'id' => 1,
'user_id' => 1,
'title' => 'First Plugin Article',
'body' => 'First Plugin Article Body',
'published' => 'Y',
'created' => '2008-09-24 10:39:23',
'updated' => '2008-09-24 10:41:31'
),
'User' => array(
'id' => 1,
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'TestPluginComment' => array(
array(
'id' => 1,
'article_id' => 1,
'user_id' => 2,
'comment' => 'First Comment for First Plugin Article',
'published' => 'Y',
'created' => '2008-09-24 10:45:23',
'updated' => '2008-09-24 10:47:31'
),
array(
'id' => 2,
'article_id' => 1,
'user_id' => 4,
'comment' => 'Second Comment for First Plugin Article',
'published' => 'Y',
'created' => '2008-09-24 10:47:23',
'updated' => '2008-09-24 10:49:31'
),
array(
'id' => 3,
'article_id' => 1,
'user_id' => 1,
'comment' => 'Third Comment for First Plugin Article',
'published' => 'Y',
'created' => '2008-09-24 10:49:23',
'updated' => '2008-09-24 10:51:31'
),
array(
'id' => 4,
'article_id' => 1,
'user_id' => 1,
'comment' => 'Fourth Comment for First Plugin Article',
'published' => 'N',
'created' => '2008-09-24 10:51:23',
'updated' => '2008-09-24 10:53:31'
))),
array(
'TestPluginArticle' => array(
'id' => 2,
'user_id' => 3,
'title' => 'Second Plugin Article',
'body' => 'Second Plugin Article Body',
'published' => 'Y',
'created' => '2008-09-24 10:41:23',
'updated' => '2008-09-24 10:43:31'
),
'User' => array(
'id' => 3,
'user' => 'larry',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:20:23',
'updated' => '2007-03-17 01:22:31'
),
'TestPluginComment' => array(
array(
'id' => 5,
'article_id' => 2,
'user_id' => 1,
'comment' => 'First Comment for Second Plugin Article',
'published' => 'Y',
'created' => '2008-09-24 10:53:23',
'updated' => '2008-09-24 10:55:31'
),
array(
'id' => 6,
'article_id' => 2,
'user_id' => 2,
'comment' => 'Second Comment for Second Plugin Article',
'published' => 'Y',
'created' => '2008-09-24 10:55:23',
'updated' => '2008-09-24 10:57:31'
))),
array(
'TestPluginArticle' => array(
'id' => 3,
'user_id' => 1,
'title' => 'Third Plugin Article',
'body' => 'Third Plugin Article Body',
'published' => 'Y',
'created' => '2008-09-24 10:43:23',
'updated' => '2008-09-24 10:45:31'
),
'User' => array(
'id' => 1,
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'TestPluginComment' => array()
));
$this->assertEqual($result, $expected);
} | testPluginAssociations method
@access public
@return void | testPluginAssociations | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testGetAssociated() {
$this->loadFixtures('Article');
$Article = ClassRegistry::init('Article');
$assocTypes = array('hasMany', 'hasOne', 'belongsTo', 'hasAndBelongsToMany');
foreach ($assocTypes as $type) {
$this->assertEqual($Article->getAssociated($type), array_keys($Article->{$type}));
}
$Article->bindModel(array('hasMany' => array('Category')));
$this->assertEqual($Article->getAssociated('hasMany'), array('Comment', 'Category'));
$results = $Article->getAssociated();
$this->assertEqual(sort(array_keys($results)), array('Category', 'Comment', 'Tag'));
$Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
$this->assertEqual($Article->getAssociated('hasAndBelongsToMany'), array());
$result = $Article->getAssociated('Category');
$expected = array(
'className' => 'Category',
'foreignKey' => 'article_id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'dependent' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => '',
'association' => 'hasMany',
);
$this->assertEqual($result, $expected);
} | Tests getAssociated method
@access public
@return void | testGetAssociated | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testAutoConstructAssociations() {
$this->loadFixtures('User', 'ArticleFeatured');
$TestModel =& new AssociationTest1();
$result = $TestModel->hasAndBelongsToMany;
$expected = array('AssociationTest2' => array(
'unique' => false,
'joinTable' => 'join_as_join_bs',
'foreignKey' => false,
'className' => 'AssociationTest2',
'with' => 'JoinAsJoinB',
'associationForeignKey' => 'join_b_id',
'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '',
'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => ''
));
$this->assertEqual($result, $expected);
// Tests related to ticket https://trac.cakephp.org/ticket/5594
$TestModel =& new ArticleFeatured();
$TestFakeModel =& new ArticleFeatured(array('table' => false));
$expected = array(
'User' => array(
'className' => 'User', 'foreignKey' => 'user_id',
'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''
),
'Category' => array(
'className' => 'Category', 'foreignKey' => 'category_id',
'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''
)
);
$this->assertIdentical($TestModel->belongsTo, $expected);
$this->assertIdentical($TestFakeModel->belongsTo, $expected);
$this->assertEqual($TestModel->User->name, 'User');
$this->assertEqual($TestFakeModel->User->name, 'User');
$this->assertEqual($TestModel->Category->name, 'Category');
$this->assertEqual($TestFakeModel->Category->name, 'Category');
$expected = array(
'Featured' => array(
'className' => 'Featured',
'foreignKey' => 'article_featured_id',
'conditions' => '',
'fields' => '',
'order' => '',
'dependent' => ''
));
$this->assertIdentical($TestModel->hasOne, $expected);
$this->assertIdentical($TestFakeModel->hasOne, $expected);
$this->assertEqual($TestModel->Featured->name, 'Featured');
$this->assertEqual($TestFakeModel->Featured->name, 'Featured');
$expected = array(
'Comment' => array(
'className' => 'Comment',
'dependent' => true,
'foreignKey' => 'article_featured_id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
));
$this->assertIdentical($TestModel->hasMany, $expected);
$this->assertIdentical($TestFakeModel->hasMany, $expected);
$this->assertEqual($TestModel->Comment->name, 'Comment');
$this->assertEqual($TestFakeModel->Comment->name, 'Comment');
$expected = array(
'Tag' => array(
'className' => 'Tag',
'joinTable' => 'article_featureds_tags',
'with' => 'ArticleFeaturedsTag',
'foreignKey' => 'article_featured_id',
'associationForeignKey' => 'tag_id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
));
$this->assertIdentical($TestModel->hasAndBelongsToMany, $expected);
$this->assertIdentical($TestFakeModel->hasAndBelongsToMany, $expected);
$this->assertEqual($TestModel->Tag->name, 'Tag');
$this->assertEqual($TestFakeModel->Tag->name, 'Tag');
} | testAutoConstructAssociations method
@access public
@return void | testAutoConstructAssociations | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testConstruct() {
$this->loadFixtures('Post', 'Comment');
$TestModel =& ClassRegistry::init('MergeVarPluginPost');
$this->assertEqual($TestModel->actsAs, array('Containable', 'Tree'));
$this->assertTrue(isset($TestModel->Behaviors->Containable));
$this->assertTrue(isset($TestModel->Behaviors->Tree));
$TestModel =& ClassRegistry::init('MergeVarPluginComment');
$expected = array('Containable', 'Containable' => array('some_settings'));
$this->assertEqual($TestModel->actsAs, $expected);
$this->assertTrue(isset($TestModel->Behaviors->Containable));
} | test Model::__construct
ensure that $actsAS and $_findMethods are merged.
@return void | testConstruct | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testConstructWithAlternateDataSource() {
$TestModel =& ClassRegistry::init(array(
'class' => 'DoesntMatter', 'ds' => 'test_suite', 'table' => false
));
$this->assertEqual('test_suite', $TestModel->useDbConfig);
//deprecated but test it anyway
$NewVoid =& new TheVoid(null, false, 'other');
$this->assertEqual('other', $NewVoid->useDbConfig);
} | test Model::__construct
ensure that $actsAS and $_findMethods are merged.
@return void | testConstructWithAlternateDataSource | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
function testColumnTypeFetching() {
$model =& new Test();
$this->assertEqual($model->getColumnType('id'), 'integer');
$this->assertEqual($model->getColumnType('notes'), 'text');
$this->assertEqual($model->getColumnType('updated'), 'datetime');
$this->assertEqual($model->getColumnType('unknown'), null);
$model =& new Article();
$this->assertEqual($model->getColumnType('User.created'), 'datetime');
$this->assertEqual($model->getColumnType('Tag.id'), 'integer');
$this->assertEqual($model->getColumnType('Article.id'), 'integer');
} | testColumnTypeFetching method
@access public
@return void | testColumnTypeFetching | php | Datawalke/Coordino | cake/tests/cases/libs/model/model_integration.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.