2 defined('AK_TEST_DATABASE_ON') ?
null : define('AK_TEST_DATABASE_ON', true);
3 require_once(dirname(__FILE__
).'/../../fixtures/config/config.php');
5 require_once(AK_LIB_DIR
.DS
.'AkUnitTest.php');
7 class Test_of_AkUnitTest
extends AkUnitTest
9 function test_should_create_models_on_the_fly()
11 $unit_tester = new AkUnitTest();
12 $this->assertFalse(class_exists('SomeSillyModel'));
13 $unit_tester->installAndIncludeModels(array('SomeSillyModel'=>'id,body'));
14 $this->assertTrue(class_exists('SomeSillyModel'));
15 $this->assertTrue($someModel = new SomeSillyModel());
16 $this->assertEqual($someModel->getTableName(),'some_silly_models');
17 $this->assertTrue($someModel->hasColumn('id'));
18 $this->assertTrue($someModel->hasColumn('body'));
19 $this->assertTrue($someModel->create(array('body'=>'something')));
20 $this->assertTrue($someModel->find('first',array('body'=>'something')));
22 $unit_tester->installAndIncludeModels(array('SomeSillyModel'=>'id,body'));
23 $this->assertNoErrors();
24 $this->assertFalse($someModel->find('all'));
27 function test_should_instantiate_Model()
29 $unit_tester = new AkUnitTest();
30 $this->assertFalse(isset($unit_tester->Account
));
31 $unit_tester->instantiateModel('Account');
32 $this->assertTrue(isset($unit_tester->Account
));
33 $this->assertTrue(AkActiveRecord
::descendsFromActiveRecord($unit_tester->Account
));
35 $this->assertFalse($unit_tester->instantiateModel('AnotherModel'));
36 $this->assertError('Could not instantiate AnotherModel');
37 $this->assertFalse(isset($unit_tester->AnotherModel
));
39 $unit_tester->instantiateModel('SomeSillyModel');
40 $this->assertTrue(isset($unit_tester->SomeSillyModel
));
43 function test_should_produce_some_errors()
45 $unit_tester = new AkUnitTest();
46 $unit_tester->installAndIncludeModels('Illegal Name');
47 $this->assertError('Could not install the table illegal_names for the model Illegal Name');
48 $this->assertError('Could not declare the model Illegal Name.');
49 $this->assertError('Could not instantiate Illegal Name');
51 $unit_tester->installAndIncludeModels('AnotherModel',array('instantiate'=>false));
52 $this->assertError('Could not install the table another_models for the model AnotherModel');
55 function test_should_fill_the_table_with_yaml_data()
57 $unit_tester = new AkUnitTest();
58 $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'));
59 $TheModel =& $unit_tester->TheModel
;
60 $TheModel->create(array('name'=>'eins'));
61 $TheModel->create(array('name'=>'zwei'));
62 $TheModel->create(array('name'=>'drei'));
63 $TheModel->create(array('name'=>'vier'));
64 $this->assertEqual($TheModel->count(),4);
66 $this->assertTrue($AllRecords = $TheModel->find());
67 $yaml = $TheModel->toYaml($AllRecords);
68 $this->assertFalse(file_exists(AK_TEST_DIR
.DS
.'fixtures'.DS
.'data'.DS
.'the_models.yaml'));
69 Ak
::file_put_contents(AK_TEST_DIR
.DS
.'fixtures'.DS
.'data'.DS
.'the_models.yaml',$yaml);
71 $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'));
72 $this->assertFalse($TheModel->find());
73 $this->assertEqual($TheModel->count(),0);
75 $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'),array('populate'=>true));
76 $this->assertEqual($TheModel->count(),4);
77 unlink(AK_TEST_DIR
.DS
.'fixtures'.DS
.'data'.DS
.'the_models.yaml');
81 function test_should_instantiate_selected_models()
83 $models = array('Picture', 'Landlord');
85 $unit_tester =& new AkUnitTest();
86 $unit_tester->includeAndInstatiateModels($models);
87 foreach ($models as $model){
88 $this->assertTrue(isset($unit_tester->$model));
89 $this->assertTrue(AkActiveRecord
::descendsFromActiveRecord($unit_tester->$model));
92 $unit_tester =& new AkUnitTest();
93 $unit_tester->includeAndInstatiateModels(join(',',$models));
94 foreach ($models as $model){
95 $this->assertTrue(isset($unit_tester->$model));
96 $this->assertTrue(AkActiveRecord
::descendsFromActiveRecord($unit_tester->$model));
101 function test_should_run_migration_up_and_down()
103 $unit_tester =& new AkUnitTest();
104 $unit_tester->includeAndInstatiateModels('Picture');
106 $this->assertTrue($unit_tester->Picture
->create(array('title'=>__FUNCTION__
)));
107 $this->assertTrue($unit_tester->Picture
->find('first',array('title'=>__FUNCTION__
)));
109 $unit_tester->uninstallAndInstallMigration('Picture');
110 $this->assertNoErrors();
111 $this->assertFalse($unit_tester->Picture
->find('all'));
115 ak_test('Test_of_AkUnitTest', true);