3 require_once 'PHPUnit/Framework.php';
4 require_once ISSO
. '/Api.php';
10 * @copyright Copyright (c)2002 - 2007, Blue Static
14 class ApiTest
extends PHPUnit_Framework_TestCase
19 public function setUp()
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();
26 CREATE TABLE pre_apitest
30 avarchar varchar(200) not null,
32 abool boolean not null,
33 aint integer not null,
34 afloat float not null,
40 public function tearDown()
42 $this->db
->query("DROP TABLE pre_apitest");
43 $this->fixture
= null
;
46 public function testInsert()
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();
57 public function testMissingFields()
59 $this->fixture
->set('atext', 'moocow');
62 $this->fixture
->insert();
63 $this->fail('exception expected');
65 catch (ApiException
$e)
69 public function testCondition()
72 $this->fixture
->set('a')
76 class TestApiFixture
extends BSApi
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
)
88 protected $table = 'apitest';
90 protected $prefix = 'pre_';
92 public function T_getCondition()
94 return $this->condition
;