1 | <?php | 1 | <?php |
2 | /* | 2 | /* |
3 | * Created on 2008 Apr 30 | 3 | * Created on 2008 Apr 30 |
4 | * by Martin Wernstahl <m4rw3r@gmail.com> | 4 | * by Martin Wernstahl <m4rw3r@gmail.com> |
5 | */ | 5 | */ |
6 | class irtest extends Controller{ | 6 | class irtest extends Controller{ |
7 | function irtest(){ | 7 | function irtest(){ |
8 | parent::Controller(); | 8 | parent::Controller(); |
9 | $this->load->database(); | 9 | $this->load->database(); |
10 | $this->load->library('unit_test'); | 10 | $this->load->library('unit_test'); |
11 | $this->unit->use_strict(TRUE); | 11 | $this->unit->use_strict(TRUE); |
12 | $this->output->enable_profiler(TRUE); | 12 | $this->output->enable_profiler(TRUE); |
13 | } | 13 | } |
14 | /** | 14 | /** |
15 | * Test suite for IgnitedRecord. | 15 | * Test suite for IgnitedRecord. |
16 | */ | 16 | */ |
17 | function index(){ | 17 | function index(){ |
18 | // set up test tables: | 18 | // set up test tables: |
19 | /*$this->db->query( | 19 | /*$this->db->query( |
20 | 'DROP TABLE IF EXISTS `test_posts`; | 20 | 'DROP TABLE IF EXISTS `test_posts`; |
21 | CREATE TABLE "test_posts" ( | 21 | CREATE TABLE "test_posts" ( |
22 | "id" int(10) unsigned NOT NULL auto_increment, | 22 | "id" int(10) unsigned NOT NULL auto_increment, |
23 | "text" varchar(300) NOT NULL, | 23 | "text" varchar(300) NOT NULL, |
24 | "test_users_id" int(10) unsigned NOT NULL, | 24 | "test_users_id" int(10) unsigned NOT NULL, |
25 | PRIMARY KEY ("id") | 25 | PRIMARY KEY ("id") |
26 | ) AUTO_INCREMENT=1 ;'); | 26 | ) AUTO_INCREMENT=1 ;'); |
27 | $this->db->query( | 27 | $this->db->query( |
28 | 'DROP TABLE IF EXISTS `test_users`; | 28 | 'DROP TABLE IF EXISTS `test_users`; |
29 | CREATE TABLE "test_users" ( | 29 | CREATE TABLE "test_users" ( |
30 | "id" int(10) unsigned NOT NULL auto_increment, | 30 | "id" int(10) unsigned NOT NULL auto_increment, |
31 | "name" varchar(200) NOT NULL, | 31 | "name" varchar(200) NOT NULL, |
32 | "email" varchar(200) NOT NULL, | 32 | "email" varchar(200) NOT NULL, |
33 | PRIMARY KEY ("id") | 33 | PRIMARY KEY ("id") |
34 | ) AUTO_INCREMENT=1 ;');*/ | 34 | ) AUTO_INCREMENT=1 ;');*/ |
35 | | 35 | |
36 | // start test | 36 | // start test |
37 | $this->load->orm(); | 37 | $this->load->orm(); |
38 | $this->unit->run(class_exists('IgnitedRecord'), | 38 | $this->unit->run(class_exists('IgnitedRecord'), |
39 | true,'Loading of Ignitedrecord'); | 39 | true,'Loading of Ignitedrecord'); |
40 | | 40 | |
41 | $this->user = IgnitedRecord::yamlfactory( | 41 | $this->user = IgnitedRecord::yamlfactory( |
42 | 'table: test_users | 42 | 'table: test_users |
43 | habtm: | 43 | habtm: |
44 | -name: lol | 44 | -name: lol |
45 | table: test_habtm | 45 | table: test_habtm |
46 | model: blaaaa | 46 | model: blaaaa |
47 | '); | 47 | '); |
48 | $this->unit->run(isset($this->user) && $this->user instanceof IgnitedRecord, | 48 | $this->unit->run(isset($this->user) && $this->user instanceof IgnitedRecord, |
49 | true,'Creating a model with the yamlfactory() method'); | 49 | true,'Creating a model with the yamlfactory() method'); |
50 | $this->unit->run($this->user->__table, | 50 | $this->unit->run($this->user->__table, |
51 | 'test_users','Checking __table is correctly set'); | 51 | 'test_users','Checking __table is correctly set'); |
52 | | 52 | |
53 | | 53 | |
54 | $this->post = IgnitedRecord::factory('test_posts', | 54 | $this->post = IgnitedRecord::factory('test_posts', |
55 | array('belongs_to' => 'test_users', | 55 | array('belongs_to' => 'test_users', |
56 | 'habtm' => array('name' => 'lol','table' => 'test_habtm','model' => 'user') | 56 | 'habtm' => array('name' => 'lol','table' => 'test_habtm','model' => 'user') |
57 | )); | 57 | )); |
58 | $this->unit->run(isset($this->post) && $this->post instanceof IgnitedRecord, | 58 | $this->unit->run(isset($this->post) && $this->post instanceof IgnitedRecord, |
59 | true,'Creating a model with the factory() method'); | 59 | true,'Creating a model with the factory() method'); |
60 | $this->unit->run($this->post->__table, | 60 | $this->unit->run($this->post->__table, |
61 | 'test_posts','Checking __table is correctly set'); | 61 | 'test_posts','Checking __table is correctly set'); |
62 | | 62 | |
63 | echo $this->unit->summary_report(); | 63 | echo $this->unit->summary_report(); |
64 | } | 64 | } |
65 | } | 65 | } |