0
@@ -32,18 +32,32 @@ class CmsObjectRelationalMappingTest extends PHPUnit_Framework_TestCase
0
another_test_field C(255),
0
$cms_db_prefix = CMS_DB_PREFIX;
0
- cms_db()->Execute("INSERT INTO {$cms_db_prefix}test_orm_table (test_field, another_test_field,
create_date, modified_date) VALUES ('test', 'blah', now() - 10, now() - 10)");
0
+ cms_db()->Execute("INSERT INTO {$cms_db_prefix}test_orm_table (test_field, another_test_field,
some_int, some_float, create_date, modified_date) VALUES ('test', 'blah', 5, 5.501, now() - 10, now() - 10)");
0
cms_db()->Execute("INSERT INTO {$cms_db_prefix}test_orm_table (test_field, create_date, modified_date) VALUES ('test2', now(), now())");
0
cms_db()->Execute("INSERT INTO {$cms_db_prefix}test_orm_table (test_field, create_date, modified_date) VALUES ('test3', now(), now())");
0
+ @CmsDatabase::drop_table('test_orm_table_child');
0
+ CmsDatabase::create_table('test_orm_table_child', "
0
+ some_other_field C(255),
0
+ cms_db()->Execute("INSERT INTO {$cms_db_prefix}test_orm_table_child (parent_id, some_other_field, create_date, modified_date) VALUES (1, 'test', now(), now())");
0
public function tearDown()
0
+ CmsDatabase::drop_table('test_orm_table_child');
0
CmsDatabase::drop_table('test_orm_table');
0
@@ -57,7 +71,7 @@ class CmsObjectRelationalMappingTest extends PHPUnit_Framework_TestCase
0
public function testGetColumnsInTableShouldWork()
0
$result = cms_orm('test_orm_table')->get_columns_in_table();
0
- $this->assertEquals(
5, count($result));
0
+ $this->assertEquals(
7, count($result));
0
$this->assertEquals('int', $result['id']->type);
0
$this->assertEquals('varchar', $result['test_field']->type);
0
$this->assertEquals('datetime', $result['create_date']->type);
0
@@ -168,12 +182,89 @@ class CmsObjectRelationalMappingTest extends PHPUnit_Framework_TestCase
0
$this->assertTrue($result->has_parameter('modified_date'));
0
$this->assertFalse($result->has_parameter('i_made_this_up'));
0
+ public function testValidatorWillNotAllowSaves()
0
+ $result = cms_orm('test_orm_table')->find();
0
+ $result->test_field = '';
0
+ $result->another_test_field = '';
0
+ $this->assertFalse($result->save());
0
+ $result->test_field = 'test';
0
+ $this->assertFalse($result->save());
0
+ $result->another_test_field = 'blah';
0
+ $this->assertTrue($result->save());
0
+ public function testNumericalityOfValidatorShouldActuallyWork()
0
+ $result = cms_orm('test_orm_table')->find();
0
+ $result->some_int = ''; #We're testing numbers, not empty strings -- do another validation
0
+ $this->assertTrue($result->save());
0
+ $result->some_int = '5';
0
+ $this->assertTrue($result->save());
0
+ $result->some_int = 5;
0
+ $this->assertTrue($result->save());
0
+ $result->some_float = 'sdfsdfsdfsfd';
0
+ $this->assertFalse($result->save());
0
+ $result->some_float = '5.501';
0
+ $this->assertTrue($result->save());
0
+ $result->some_float = 5.501;
0
+ $this->assertTrue($result->save());
0
+ public function testHasManyShouldWork()
0
+ $result = cms_orm('test_orm_table')->find_by_id(1);
0
+ $this->assertNotNull($result);
0
+ $this->assertEquals(1, count($result->children));
0
+ $this->assertEquals('test', $result->children[0]->some_other_field);
0
+ public function testBelongsToShouldWorkAsWell()
0
+ $result = cms_orm('test_orm_table')->find_by_id(1);
0
+ $this->assertNotNull($result);
0
+ $this->assertEquals(1, count($result->children));
0
+ $this->assertNotNull(count($result->children[0]->parent));
0
+ $this->assertEquals(1, $result->children[0]->parent->id);
0
+ public function testDeleteShouldActuallyDelete()
0
+ $result = cms_orm('test_orm_table')->find_by_id(1);
0
+ $this->assertNotNull($result);
0
+ $result = cms_orm('test_orm_table')->find_all();
0
+ $this->assertEquals(2, count($result));
0
class TestOrmTable extends CmsObjectRelationalMapping
0
+ public function setup()
0
+ $this->create_has_many_association('children', 'TestOrmTableChild', 'parent_id');
0
+ public function validate()
0
+ $this->validate_not_blank('test_field');
0
+ if (strlen($this->another_test_field) == 0)
0
+ $this->add_validation_error('can\'t be blank');
0
+ $this->validate_numericality_of('some_int');
0
+ $this->validate_numericality_of('some_float');
0
+class TestOrmTableChild extends CmsObjectRelationalMapping
0
+ public function setup()
0
+ $this->create_belongs_to_association('parent', 'test_orm_table', 'parent_id');
Comments
No one has commented yet.