mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-04 10:32:40 +00:00
parent
90af608489
commit
8b4e79c795
6 changed files with 363 additions and 1 deletions
|
@ -623,6 +623,158 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->assertEquals($TestModel->Comment->find('all'), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test HABM operations without clobbering existing records #275
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testHABTMKeepExisting() {
|
||||
$this->loadFixtures('Site', 'Domain', 'DomainsSite');
|
||||
|
||||
$Site = new Site();
|
||||
$results = $Site->find('count');
|
||||
$expected = 3;
|
||||
$this->assertEquals($results, $expected);
|
||||
|
||||
$data = $Site->findById(1);
|
||||
|
||||
// include api.cakephp.org
|
||||
$data['Domain'] = array('Domain' => array(1, 2, 3));
|
||||
$Site->save($data);
|
||||
|
||||
$Site->id = 1;
|
||||
$results = $Site->read();
|
||||
$expected = 3; // 3 domains belonging to cakephp
|
||||
$this->assertEquals($expected, count($results['Domain']));
|
||||
|
||||
|
||||
$Site->id = 2;
|
||||
$results = $Site->read();
|
||||
$expected = 2; // 2 domains belonging to markstory
|
||||
$this->assertEquals($expected, count($results['Domain']));
|
||||
|
||||
$Site->id = 3;
|
||||
$results = $Site->read();
|
||||
$expected = 2;
|
||||
$this->assertEquals($expected, count($results['Domain']));
|
||||
$results['Domain'] = array('Domain' => array(7));
|
||||
$Site->save($results); // remove association from domain 6
|
||||
$results = $Site->read();
|
||||
$expected = 1; // only 1 domain left belonging to rchavik
|
||||
$this->assertEquals($expected, count($results['Domain']));
|
||||
|
||||
// add deleted domain back
|
||||
$results['Domain'] = array('Domain' => array(6, 7));
|
||||
$Site->save($results);
|
||||
$results = $Site->read();
|
||||
$expected = 2; // 2 domains belonging to rchavik
|
||||
$this->assertEquals($expected, count($results['Domain']));
|
||||
|
||||
$Site->DomainsSite->id = $results['Domain'][0]['DomainsSite']['id'];
|
||||
$Site->DomainsSite->saveField('active', true);
|
||||
|
||||
$results = $Site->Domain->DomainsSite->find('count', array(
|
||||
'conditions' => array(
|
||||
'DomainsSite.active' => true,
|
||||
),
|
||||
));
|
||||
$expected = 5;
|
||||
$this->assertEquals($expected, $results);
|
||||
|
||||
// activate api.cakephp.org
|
||||
$activated = $Site->DomainsSite->findByDomainId(3);
|
||||
$activated['DomainsSite']['active'] = true;
|
||||
$Site->DomainsSite->save($activated);
|
||||
|
||||
$results = $Site->DomainsSite->find('count', array(
|
||||
'conditions' => array(
|
||||
'DomainsSite.active' => true,
|
||||
),
|
||||
));
|
||||
$expected = 6;
|
||||
$this->assertEquals($expected, $results);
|
||||
|
||||
// remove 2 previously active domains, and leave $activated alone
|
||||
$data = array(
|
||||
'Site' => array('id' => 1, 'name' => 'cakephp (modified)'),
|
||||
'Domain' => array(
|
||||
'Domain' => array(3),
|
||||
)
|
||||
);
|
||||
$Site->create($data);
|
||||
$Site->save($data);
|
||||
|
||||
// tests that record is still identical prior to removal
|
||||
$Site->id = 1;
|
||||
$results = $Site->read();
|
||||
unset($results['Domain'][0]['DomainsSite']['updated']);
|
||||
unset($activated['DomainsSite']['updated']);
|
||||
$this->assertEquals($activated['DomainsSite'], $results['Domain'][0]['DomainsSite']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test HABM operations without clobbering existing records #275
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testHABTMKeepExistingWithThreeDbs() {
|
||||
$config = ConnectionManager::enumConnectionObjects();
|
||||
$this->skipIf(
|
||||
!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']),
|
||||
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
|
||||
);
|
||||
|
||||
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer');
|
||||
$Player = ClassRegistry::init('Player');
|
||||
$Player->bindModel(array(
|
||||
'hasAndBelongsToMany' => array(
|
||||
'Armor' => array(
|
||||
'with' => 'ArmorsPlayer',
|
||||
'unique' => 'keepExisting',
|
||||
),
|
||||
),
|
||||
), false);
|
||||
$this->assertEquals('test', $Player->useDbConfig);
|
||||
$this->assertEquals('test', $Player->Guild->useDbConfig);
|
||||
$this->assertEquals('test2', $Player->Guild->GuildsPlayer->useDbConfig);
|
||||
$this->assertEquals('test2', $Player->Armor->useDbConfig);
|
||||
$this->assertEquals('test_database_three', $Player->ArmorsPlayer->useDbConfig);
|
||||
|
||||
$players = $Player->find('all');
|
||||
$this->assertEquals(4 , count($players));
|
||||
$playersGuilds = Set::extract('/Guild/GuildsPlayer', $players);
|
||||
$this->assertEquals(3 , count($playersGuilds));
|
||||
$playersArmors = Set::extract('/Armor/ArmorsPlayer', $players);
|
||||
$this->assertEquals(3 , count($playersArmors));
|
||||
unset($players);
|
||||
|
||||
$larry = $Player->findByName('larry');
|
||||
$larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry);
|
||||
$this->assertEquals(1 , count($larrysArmor));
|
||||
|
||||
$larry['Guild']['Guild'] = array(1, 3); // larry joins another guild
|
||||
$larry['Armor']['Armor'] = array(2, 3); // purchases chainmail
|
||||
$Player->save($larry);
|
||||
unset($larry);
|
||||
|
||||
$larry = $Player->findByName('larry');
|
||||
$larrysGuild = Set::extract('/Guild/GuildsPlayer', $larry);
|
||||
$this->assertEquals(2 , count($larrysGuild));
|
||||
$larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry);
|
||||
$this->assertEquals(2 , count($larrysArmor));
|
||||
|
||||
$larrysArmorsPlayersIds = Set::extract('/Armor/ArmorsPlayer/id', $larry);
|
||||
|
||||
$Player->ArmorsPlayer->id = 3;
|
||||
$Player->ArmorsPlayer->saveField('broken', true); // larry's cloak broke
|
||||
|
||||
$larry = $Player->findByName('larry');
|
||||
$larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry);
|
||||
$larrysCloak = Set::extract('/ArmorsPlayer[armor_id=3]', $larrysArmor);
|
||||
$this->assertNotEmpty($larrysCloak);
|
||||
$this->assertTrue($larrysCloak[0]['ArmorsPlayer']['broken']); // still broken
|
||||
}
|
||||
|
||||
/**
|
||||
* testDisplayField method
|
||||
*
|
||||
|
|
|
@ -70,7 +70,7 @@ abstract class BaseModelTest extends CakeTestCase {
|
|||
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
|
||||
'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all',
|
||||
'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player',
|
||||
'core.bidding', 'core.bidding_message'
|
||||
'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -3279,6 +3279,24 @@ class TransactionManyTestModel extends CakeTestModel {
|
|||
}
|
||||
}
|
||||
|
||||
class Site extends CakeTestModel {
|
||||
var $name = 'Site';
|
||||
var $useTable = 'sites';
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Domain' => array('unique' => 'keepExisting'),
|
||||
);
|
||||
}
|
||||
|
||||
class Domain extends CakeTestModel {
|
||||
var $name = 'Domain';
|
||||
var $useTable = 'domains';
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Site' => array('unique' => 'keepExisting'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* TestModel class
|
||||
*
|
||||
|
|
65
lib/Cake/Test/Fixture/DomainFixture.php
Normal file
65
lib/Cake/Test/Fixture/DomainFixture.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* PHP versions 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since CakePHP(tm) v 2.1
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class DomainFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Domain'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Domain';
|
||||
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'domain' => array('type' => 'string', 'null' => false),
|
||||
'created' => 'datetime',
|
||||
'updated' => 'datetime'
|
||||
);
|
||||
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('domain' => 'cakephp.org', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('domain' => 'book.cakephp.org', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('domain' => 'api.cakephp.org', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('domain' => 'mark-story.com', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
|
||||
array('domain' => 'tinadurocher.com', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
|
||||
array('domain' => 'chavik.com', 'created' => '2001-02-03 00:01:02', 'updated' => '2007-03-17 01:22:31'),
|
||||
array('domain' => 'xintesa.com', 'created' => '2001-02-03 00:01:02', 'updated' => '2007-03-17 01:22:31'),
|
||||
);
|
||||
}
|
66
lib/Cake/Test/Fixture/DomainsSiteFixture.php
Normal file
66
lib/Cake/Test/Fixture/DomainsSiteFixture.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* PHP versions 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since CakePHP(tm) v 2.1
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class DomainsSiteFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Domain'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'DomainsSite';
|
||||
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'domain_id' => array('type' => 'integer', 'null' => false),
|
||||
'site_id' => array('type' => 'integer', 'null' => false),
|
||||
'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
|
||||
'created' => 'datetime',
|
||||
'updated' => 'datetime',
|
||||
);
|
||||
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('site_id' => 1, 'domain_id' => 1, 'active' => true, 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('site_id' => 1, 'domain_id' => 2, 'active' => true, 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('site_id' => 2, 'domain_id' => 4, 'active' => true, 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
|
||||
array('site_id' => 2, 'domain_id' => 5, 'active' => true, 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
|
||||
array('site_id' => 3, 'domain_id' => 6, 'active' => true, 'created' => '2001-02-03 00:01:02', 'updated' => '2007-03-17 01:22:31'),
|
||||
array('site_id' => 3, 'domain_id' => 7, 'active' => false, 'created' => '2001-02-03 00:01:02', 'updated' => '2007-03-17 01:22:31'),
|
||||
);
|
||||
}
|
61
lib/Cake/Test/Fixture/SiteFixture.php
Normal file
61
lib/Cake/Test/Fixture/SiteFixture.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* PHP versions 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since CakePHP(tm) v 2.1
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class SiteFixture extends CakeTestFixture {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Site'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Site';
|
||||
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'null' => false),
|
||||
'created' => 'datetime',
|
||||
'updated' => 'datetime'
|
||||
);
|
||||
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('name' => 'cakephp', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
array('name' => 'Mark Story\'s sites', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
|
||||
array('name' => 'rchavik sites', 'created' => '2001-02-03 00:01:02', 'updated' => '2007-03-17 01:22:31'),
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue