array( "database.adapter" => "mysqli", "database.params.host" => "localhost", "database.params.dbname" => "database_test", "database.params.username" => "root", "database.params.password" => "root", ) ); private $error; public function makeFaulty() { $this->api->db->config('localhost', 'test', 'test', 'database_test'); } public function setUp() { $this->api = Asra_Core_Api::getInstance(); $this->api->init(false, $this->config); $this->api->setCacheDir(null); $this->api->setLogDir(null); } public function tearDown() { } public function test__clone() { $this->setExpectedException('ReflectionException'); $api = Asra_Core_Api::getInstance(); $method = new ReflectionMethod('Asra_Core_Api', '__clone'); $this->assertTrue($method->isFinal()); $this->assertTrue($method->isPrivate()); $method->invoke($api); } public function test__construct() { $this->setExpectedException('ReflectionException'); $class = new ReflectionClass('Asra_Core_Api'); $instance = $class->newInstance(); clone $instance; } public function testCacheDir() { $this->api->setCacheDir(FILES . 'apps/default_app/cache'); $this->assertEquals(FILES . 'apps/default_app/cache/', $this->api->getCacheDir()); } public function testCannotConnect() { $db = $this->api->db->selectdb('non_existent_database'); $this->assertFalse($db); $this->makeFaulty(); $result = $this->api->query('SELECT * FROM `table_name`'); } public function testClean() { $rows = $this->api->run('SELECT * FROM `table_name`'); $rows = $this->api->clean($rows); $this->assertType('array', $rows); } public function testClearCache() { $d = FILES . 'apps/default_app/cache'; $n = 'test.cache.xml'; $this->api->setCacheDir($d); $f = $this->api->getCacheDir() . $n; Asra_Utils_Filesystem::fileWrite($f, 'content'); $this->assertFileExists($f); $p = '/xml/test/cache'; $this->api->clearCache($p); $this->assertFileNotExists($f); } public function testClearCaches() { $d = FILES . 'apps/default_app/cache'; $n = 'test.cache.xml'; $this->api->setCacheDir($d); $f = $this->api->getCacheDir() . $n; Asra_Utils_Filesystem::fileWrite($f, 'content'); $this->assertFileExists($f); $this->api->clearCaches(); $this->assertFileNotExists($f); } public function testCount() { $count = $this->api->count('table_name'); } public function testCountCannotConnect() { $this->makeFaulty(); $count = $this->api->count('table_name'); } public function testCountNoTable() { $count = $this->api->count('no_table'); } public function testDeleteCache() { $d = FILES . 'apps/default_app/cache'; $n = 'test.cache.xml'; $this->api->setCacheDir($d); $f = $this->api->getCacheDir() . $n; Asra_Utils_Filesystem::fileWrite($f, 'content'); $this->assertFileExists($f); $this->api->deleteCache($n); $this->assertFileNotExists($f); } public function testDump() { $this->api->dump('table_name'); } public function testDumpCannotConnect() { $this->makeFaulty(); $count = $this->api->count('table_name'); } public function testDumpNoTable() { $this->api->dump('table_name_no'); } public function testError() { $this->api->error('Message', 1); $this->api->error('Message'); } public function testFind() { $p = array( 'conditions' => array( 'id' => 1 ), 'fields' => array('id'), 'limit' => 1, 'order' => 'id', 'default' => null, ); $result = $this->api->find('table_name', $p); $result = $this->api->find('table_name', 'id = 1'); } public function testFindCannotConnect() { $this->makeFaulty(); $result = $this->api->find('table_name'); } public function testGetCachePath() { $path = $this->api->getCachePath(); $path = $this->api->getCachePath('/xml/cache/path'); } public function testId() { $id = $this->api->id(); $this->assertNull($id); } public function testInitDebug() { $api = Asra_Core_Api::getInstance(); $api->init(true, $this->config); } public function testLog() { $this->api->setLogDir(FILES . 'apps/default_app/log'); $this->api->log('test'); } public function testLogNoDir() { $this->api->setLogDir(null); $this->setExpectedException('Asra_Core_Exception'); $this->api->log('test'); } public function testPrintOut() { $this->api->printOut(array(1, 2, 3)); } public function testPrintOutDebug() { $this->api->debug = true; $this->api->printOut(array(1, 2, 3)); } public function testNewApi() { $api = Asra_Core_Api::getInstance(); $this->assertNotNull($api); } public function testSetCacheLifetime() { $api = Asra_Core_Api::getInstance(); $api->setCacheLifetime(1000); $this->assertEquals($api->cacheLifetime, 1); $api->cachePath = '/test/to/cache/path'; $api->setCacheLifetime(1000); $this->assertEquals($api->cacheLifetime, 1000); $this->assertTrue($api->getUseCache()); $api->setCacheLifetime(false); $this->assertEquals($api->cacheLifetime, 1); $this->assertFalse($api->getUseCache()); $api->setCacheLifetime(true); $this->assertEquals($api->cacheLifetime, 1); $this->assertTrue($api->getUseCache()); } public function testSetExportType() { $api = Asra_Core_Api::getInstance(); $api->setExportType('xml'); $this->assertEquals('xml', $api->getExportType()); } /** * assert that settings change values */ public function testSetSettings() { $api = Asra_Core_Api::getInstance(); $api->setCacheDir(''); $api->setLogDir(''); $api->setLogQueries('not a boolean, but cast to true by (bool)'); $this->assertNull($api->getCacheDir()); $this->assertNull($api->getLogDir()); $this->assertTrue($api->getLogQueries()); $api->setCacheDir('/some/dir'); $api->setLogDir('/some/dir'); $api->setLogQueries(true); $this->assertEquals($api->getCacheDir(), '/some/dir/'); $this->assertEquals($api->getLogDir(), '/some/dir/'); $this->assertEquals($api->getLogQueries(), true); } }