diff options
author | Simon Holywell <[email protected]> | 2013-01-23 14:36:22 +0000 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2013-01-23 14:36:22 +0000 |
commit | 8fae01b172b5c6006e6f96383f538147d73601b6 (patch) | |
tree | d1710b9c426a5e6f8ff79d2a09e4a38ee2342061 /test/ConfigTest.php | |
parent | b10aff0001e61565831cc0578d4a939619f59643 (diff) | |
parent | f5e4e1d6e8b8c5b4bccc5033524c26a628465d47 (diff) |
Merge branch 'develop' into multiple-connections
Conflicts:
test/test_classes.php
test/test_queries.php
Diffstat (limited to 'test/ConfigTest.php')
-rw-r--r-- | test/ConfigTest.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/test/ConfigTest.php b/test/ConfigTest.php new file mode 100644 index 0000000..83194b4 --- /dev/null +++ b/test/ConfigTest.php @@ -0,0 +1,100 @@ +<?php + +class ConfigTest extends PHPUnit_Framework_TestCase { + + public function setUp() { + // Enable logging + ORM::configure('logging', true); + + // Set up the dummy database connection + $db = new MockPDO('sqlite::memory:'); + ORM::set_db($db); + + ORM::configure('id_column', 'primary_key'); + } + + public function tearDown() { + ORM::configure('logging', false); + ORM::set_db(null); + + ORM::configure('id_column', 'id'); + } + + protected function setUpIdColumnOverrides() { + ORM::configure('id_column_overrides', array( + 'widget' => 'widget_id', + 'widget_handle' => 'widget_handle_id', + )); + } + + protected function tearDownIdColumnOverrides() { + ORM::configure('id_column_overrides', array()); + } + + public function testSettingIdColumn() { + ORM::for_table('widget')->find_one(5); + $expected = "SELECT * FROM `widget` WHERE `primary_key` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + } + + public function testSettingIdColumnOverridesOne() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget')->find_one(5); + $expected = "SELECT * FROM `widget` WHERE `widget_id` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + + public function testSettingIdColumnOverridesTwo() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget_handle')->find_one(5); + $expected = "SELECT * FROM `widget_handle` WHERE `widget_handle_id` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + + public function testSettingIdColumnOverridesThree() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget_nozzle')->find_one(5); + $expected = "SELECT * FROM `widget_nozzle` WHERE `primary_key` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + + public function testInstanceIdColumnOne() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget')->use_id_column('new_id')->find_one(5); + $expected = "SELECT * FROM `widget` WHERE `new_id` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + + public function testInstanceIdColumnTwo() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget_handle')->use_id_column('new_id')->find_one(5); + $expected = "SELECT * FROM `widget_handle` WHERE `new_id` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + + public function testInstanceIdColumnThree() { + $this->setUpIdColumnOverrides(); + + ORM::for_table('widget_nozzle')->use_id_column('new_id')->find_one(5); + $expected = "SELECT * FROM `widget_nozzle` WHERE `new_id` = '5' LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + + $this->tearDownIdColumnOverrides(); + } + +}
\ No newline at end of file |