Skip to content

Commit

Permalink
Adding tests for loading multischema fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Nov 17, 2011
1 parent a5ac328 commit 073d049
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 1 deletion.
78 changes: 78 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -2072,4 +2072,82 @@ public function testHasMethod() {
$this->assertTrue($Article->hasMethod('pass'));
$this->assertFalse($Article->hasMethod('fail'));
}

/**
* testMultischemaFixture
*
* @return void
*/
public function testMultischemaFixture() {

$config = new DATABASE_CONFIG();
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
$this->skipIf(!isset($config->test) || !isset($config->test2),
'Primary and secondary test databases not configured, skipping cross-database join tests. To run these tests define $test and $test2 in your database configuration.'
);

$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');

$Player = ClassRegistry::init('Player');
$this->assertEqual($Player->useDbConfig, 'test');
$this->assertEqual($Player->Guild->useDbConfig, 'test');
$this->assertEqual($Player->Guild->GuildsPlayer->useDbConfig, 'test2');
$this->assertEqual($Player->GuildsPlayer->useDbConfig, 'test2');

$players = $Player->find('all', array('recursive' => -1));
$guilds = $Player->Guild->find('all', array('recursive' => -1));
$guildsPlayers = $Player->GuildsPlayer->find('all', array('recursive' => -1));

$this->assertEqual(true, count($players) > 1);
$this->assertEqual(true, count($guilds) > 1);
$this->assertEqual(true, count($guildsPlayers) > 1);
}

/**
* testMultischemaFixtureWithThreeDatabases, three databases
*
* @return void
*/
public function testMultischemaFixtureWithThreeDatabases() {

$config = new DATABASE_CONFIG();
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
$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',
),
),
), false);
$this->assertEqual('test', $Player->useDbConfig);
$this->assertEqual('test', $Player->Guild->useDbConfig);
$this->assertEqual('test2', $Player->Guild->GuildsPlayer->useDbConfig);
$this->assertEqual('test2', $Player->GuildsPlayer->useDbConfig);
$this->assertEqual('test2', $Player->Armor->useDbConfig);
$this->assertEqual('test_database_three', $Player->Armor->ArmorsPlayer->useDbConfig);
$this->assertEqual('test', $Player->getDataSource()->configKeyName);
$this->assertEqual('test', $Player->Guild->getDataSource()->configKeyName);
$this->assertEqual('test2', $Player->GuildsPlayer->getDataSource()->configKeyName);
$this->assertEqual('test2', $Player->Armor->getDataSource()->configKeyName);
$this->assertEqual('test_database_three', $Player->Armor->ArmorsPlayer->getDataSource()->configKeyName);

$players = $Player->find('all', array('recursive' => -1));
$guilds = $Player->Guild->find('all', array('recursive' => -1));
$guildsPlayers = $Player->GuildsPlayer->find('all', array('recursive' => -1));
$armorsPlayers = $Player->ArmorsPlayer->find('all', array('recursive' => -1));

$this->assertEqual(true, count($players) > 1);
$this->assertEqual(true, count($guilds) > 1);
$this->assertEqual(true, count($guildsPlayers) > 1);
$this->assertEqual(true, count($armorsPlayers) > 1);
}

}
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Model/ModelTestBase.php
Expand Up @@ -67,7 +67,8 @@ abstract class BaseModelTest extends CakeTestCase {
'core.counter_cache_user_nonstandard_primary_key',
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
'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.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',
);

/**
Expand Down
68 changes: 68 additions & 0 deletions lib/Cake/Test/Case/Model/models.php
Expand Up @@ -4532,3 +4532,71 @@ class ScaffoldTag extends CakeTestModel {
*/
public $useTable = 'tags';
}

/**
* Player class
*
* @package Cake.Test.Case.Model
*/
class Player extends CakeTestModel {
public $hasAndBelongsToMany = array(
'Guild' => array(
'with' => 'GuildsPlayer',
'unique' => true,
),
);
}

/**
* Guild class
*
* @package Cake.Test.Case.Model
*/
class Guild extends CakeTestModel {
public $hasAndBelongsToMany = array(
'Player' => array(
'with' => 'GuildsPlayer',
'unique' => true,
),
);
}

/**
* GuildsPlayer class
*
* @package Cake.Test.Case.Model
*/
class GuildsPlayer extends CakeTestModel {

public $useDbConfig = 'test2';

public $belongsTo = array(
'Player',
'Guild',
);
}

/**
* Armor class
*
* @package Cake.Test.Case.Model
*/
class Armor extends CakeTestModel {

public $useDbConfig = 'test2';

public $hasAndBelongsToMany = array(
'Player' => array('with' => 'ArmorsPlayer'),
);
}

/**
* ArmorsPlayer class
*
* @package Cake.Test.Case.Model
*/
class ArmorsPlayer extends CakeTestModel {

public $useDbConfig = 'test_database_three';

}
66 changes: 66 additions & 0 deletions lib/Cake/Test/Fixture/ArmorFixture.php
@@ -0,0 +1,66 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class ArmorFixture extends CakeTestFixture {

/**
* name property
*
* @var string 'Armor'
*/
public $name = 'Armor';

/**
* Datasource
*
* Used for Multi database fixture test
*
* @var string 'test2'
*/
public $useDbConfig = 'test2';

/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);

/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'name' => 'Leather', 'created' => '2007-03-17 01:16:23'),
array('id' => 2, 'name' => 'Chainmail', 'created' => '2007-03-17 01:18:23'),
array('id' => 3, 'name' => 'Cloak', 'created' => '2007-03-17 01:20:23'),
array('id' => 4, 'name' => 'Bikini', 'created' => '2007-03-17 01:22:23'),
);
}
67 changes: 67 additions & 0 deletions lib/Cake/Test/Fixture/ArmorsPlayerFixture.php
@@ -0,0 +1,67 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class ArmorsPlayerFixture extends CakeTestFixture {

/**
* name property
*
* @var string 'ArmorsPlayer'
*/
public $name = 'ArmorsPlayer';

/**
* Datasource
*
* Used for Multi database fixture test
*
* @var string 'test_database_three'
*/
public $useDbConfig = 'test_database_three';

/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'player_id' => array('type' => 'integer', 'null' => false),
'armor_id' => array('type' => 'integer', 'null' => false),
'broken' => array('type' => 'boolean', 'null' => false, 'default' => false),
'created' => 'datetime',
'updated' => 'datetime'
);

/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'player_id' => 1, 'armor_id' => 1, 'broken' => false),
array('id' => 2, 'player_id' => 2, 'armor_id' => 2, 'broken' => false),
array('id' => 3, 'player_id' => 3, 'armor_id' => 3, 'broken' => false),
);
}
54 changes: 54 additions & 0 deletions lib/Cake/Test/Fixture/GuildFixture.php
@@ -0,0 +1,54 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class GuildFixture extends CakeTestFixture {

/**
* name property
*
* @var string 'Guild'
*/
public $name = 'Guild';

/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
);

/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'name' => 'Warriors'),
array('id' => 2, 'name' => 'Rangers'),
array('id' => 3, 'name' => 'Wizards'),
);
}

0 comments on commit 073d049

Please sign in to comment.