Add thed API unit tests
[isso.git] / UnitTest / ApiTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4 require_once ISSO . '/Api.php';
5
6 /**
7 * ApiTest
8 *
9 * @author rsesek
10 * @copyright Copyright (c)2002 - 2007, Blue Static
11 * @package ISSO Tests
12 *
13 */
14 class ApiTest extends PHPUnit_Framework_TestCase
15 {
16 private $fixture;
17 private $db;
18
19 public function setUp()
20 {
21 $this->db = BSApp::LoadModule('DbMySql');
22 $this->db->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE);
23 $this->fixture = new TestApiFixture();
24
25 $this->db->query("
26 CREATE TABLE pre_apitest
27 (
28 id int not null,
29 atext text not null,
30 avarchar varchar(200) not null,
31 abin blob not null,
32 abool boolean not null,
33 aint integer not null,
34 afloat float not null,
35 PRIMARY KEY (id)
36 )
37 ");
38 }
39
40 public function tearDown()
41 {
42 $this->db->query("DROP TABLE pre_apitest");
43 $this->fixture = null;
44 }
45
46 public function testInsert()
47 {
48 $this->fixture->set('atext', 'moocow');
49 $this->fixture->set('avarchar', 'hello');
50 $this->fixture->set('abin', 'åß∂œ∑†å∂ƒåß∂ƒå∂ƒ');
51 $this->fixture->set('abool', true);
52 $this->fixture->set('aint', 3);
53 $this->fixture->set('afloat', 2.53);
54 $this->fixture->insert();
55 }
56
57 public function testMissingFields()
58 {
59 $this->fixture->set('atext', 'moocow');
60 try
61 {
62 $this->fixture->insert();
63 $this->fail('exception expected');
64 }
65 catch (ApiException $e)
66 {}
67 }
68
69 public function testCondition()
70 {
71
72 $this->fixture->set('a')
73 }
74 }
75
76 class TestApiFixture extends BSApi
77 {
78 protected $fields = array(
79 'id' => array(TYPE_UINT, REQ_AUTO),
80 'atext' => array(TYPE_STR, REQ_YES),
81 'avarchar' => array(TYPE_STR, REQ_YES),
82 'abin' => array(TYPE_BIN, REQ_YES),
83 'abool' => array(TYPE_BOOL, REQ_YES),
84 'aint' => array(TYPE_INT, REQ_YES),
85 'afloat' => array(TYPE_FLOAT, REQ_YES)
86 );
87
88 protected $table = 'apitest';
89
90 protected $prefix = 'pre_';
91
92 public function T_getCondition()
93 {
94 return $this->condition;
95 }
96 }
97
98 ?>