Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding tests for loading multischema fixtures

  • Loading branch information...
commit 073d04931a1f0d631716bba730dd100c094fca76 1 parent a5ac328
@rchavik rchavik authored
View
78 lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -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);
+ }
+
}
View
3  lib/Cake/Test/Case/Model/ModelTestBase.php
@@ -67,7 +67,8 @@
'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',
);
/**
View
68 lib/Cake/Test/Case/Model/models.php
@@ -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';
+
+}
View
66 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'),
+ );
+}
View
67 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),
+ );
+}
View
54 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'),
+ );
+}
View
57 lib/Cake/Test/Fixture/GuildsPlayerFixture.php
@@ -0,0 +1,57 @@
+<?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 GuildsPlayerFixture extends CakeTestFixture {
+
+/**
+ * name property
+ *
+ * @var string 'GuildsPlayer'
+ */
+ public $name = 'GuildsPlayer';
+
+ public $useDbConfig = 'test2';
+
+/**
+ * fields property
+ *
+ * @var array
+ */
+ public $fields = array(
+ 'id' => array('type' => 'integer', 'key' => 'primary'),
+ 'player_id' => array('type' => 'integer', 'null' => false),
+ 'guild_id' => array('type' => 'integer', 'null' => false),
+ );
+
+/**
+ * records property
+ *
+ * @var array
+ */
+ public $records = array(
+ array('id' => 1, 'player_id' => 1, 'guild_id' => 1),
+ array('id' => 2, 'player_id' => 1, 'guild_id' => 2),
+ array('id' => 3, 'player_id' => 4, 'guild_id' => 3),
+ );
+}
View
57 lib/Cake/Test/Fixture/PlayerFixture.php
@@ -0,0 +1,57 @@
+<?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 PlayerFixture extends CakeTestFixture {
+
+/**
+ * name property
+ *
+ * @var string 'Player'
+ */
+ public $name = 'Player';
+
+/**
+ * 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' => 'mark', 'created' => '2007-03-17 01:16:23'),
+ array('id' => 2, 'name' => 'jack', 'created' => '2007-03-17 01:18:23'),
+ array('id' => 3, 'name' => 'larry', 'created' => '2007-03-17 01:20:23'),
+ array('id' => 4, 'name' => 'jose', 'created' => '2007-03-17 01:22:23'),
+ );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.