From 4faffeda17f258a6ecdbe5dbd302fa16411a7e15 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 19 Nov 2007 09:44:56 -0500 Subject: [PATCH] Add thed API unit tests --- UnitTest/AllTests.php | 3 ++ UnitTest/ApiTest.php | 98 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 UnitTest/ApiTest.php diff --git a/UnitTest/AllTests.php b/UnitTest/AllTests.php index 93c201a..f33cf73 100644 --- a/UnitTest/AllTests.php +++ b/UnitTest/AllTests.php @@ -46,6 +46,9 @@ class AllTests require_once 'DatabaseTests.php'; $suite->addTestSuite(DatabaseTests::suite()); + require_once 'ApiTest.php'; + $suite->addTestSuite('ApiTest'); + return $suite; } } diff --git a/UnitTest/ApiTest.php b/UnitTest/ApiTest.php new file mode 100644 index 0000000..2f75673 --- /dev/null +++ b/UnitTest/ApiTest.php @@ -0,0 +1,98 @@ +db = BSApp::LoadModule('DbMySql'); + $this->db->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE); + $this->fixture = new TestApiFixture(); + + $this->db->query(" + CREATE TABLE pre_apitest + ( + id int not null, + atext text not null, + avarchar varchar(200) not null, + abin blob not null, + abool boolean not null, + aint integer not null, + afloat float not null, + PRIMARY KEY (id) + ) + "); + } + + public function tearDown() + { + $this->db->query("DROP TABLE pre_apitest"); + $this->fixture = null; + } + + public function testInsert() + { + $this->fixture->set('atext', 'moocow'); + $this->fixture->set('avarchar', 'hello'); + $this->fixture->set('abin', 'åß∂œ∑†å∂ƒåß∂ƒå∂ƒ'); + $this->fixture->set('abool', true); + $this->fixture->set('aint', 3); + $this->fixture->set('afloat', 2.53); + $this->fixture->insert(); + } + + public function testMissingFields() + { + $this->fixture->set('atext', 'moocow'); + try + { + $this->fixture->insert(); + $this->fail('exception expected'); + } + catch (ApiException $e) + {} + } + + public function testCondition() + { + + $this->fixture->set('a') + } +} + +class TestApiFixture extends BSApi +{ + protected $fields = array( + 'id' => array(TYPE_UINT, REQ_AUTO), + 'atext' => array(TYPE_STR, REQ_YES), + 'avarchar' => array(TYPE_STR, REQ_YES), + 'abin' => array(TYPE_BIN, REQ_YES), + 'abool' => array(TYPE_BOOL, REQ_YES), + 'aint' => array(TYPE_INT, REQ_YES), + 'afloat' => array(TYPE_FLOAT, REQ_YES) + ); + + protected $table = 'apitest'; + + protected $prefix = 'pre_'; + + public function T_getCondition() + { + return $this->condition; + } +} + +?> \ No newline at end of file -- 2.22.5