* @license PHP License * @package WB * @subpackage unittest */ /** * Unit Test * * TestBaseClass * * @version 0.1.0 * @package WB * @subpackage unittest */ class TestCaseBase_Config extends UnitTestCase { /** * config loader * @var WBConfig */ private $config; /** * config unserializer * @var WBConfig_Unserializer */ private $unser; /** * config serializer * @var WBConfig_Serializer */ private $ser; public function __construct() { WBClass::load('WBUnitTest_SQLUte'); WBUnitTest_SQLUte::source( __FILE__, 'construct' ); $this->config = WBClass::create('WBConfig'); $this->unser = WBClass::create('WBConfig_Unserializer'); $this->ser = WBClass::create('WBConfig_Serializer'); } /** * destruct * * Remove testing tables */ public function __destruct() { WBUnitTest_SQLUte::source( __FILE__, 'destruct' ); } public function testClassLoading() { WBClass::load('WBConfig'); $this->assertTrue(class_exists('WBConfig', false)); $this->assertIsA($this->config, 'WBConfig'); $this->assertTrue(class_exists('WBConfig_Loader', false)); $this->assertTrue(class_exists('WBConfig_Loader_File', false)); WBClass::load('WBConfig_Unserializer'); $this->assertTrue(class_exists('WBConfig_Unserializer', false)); $this->assertIsA($this->unser, 'WBConfig_Unserializer'); WBClass::load('WBConfig_Serializer'); $this->assertTrue(class_exists('WBConfig_Serializer', false)); $this->assertIsA($this->ser, 'WBConfig_Serializer'); } public function testLoadconfigTable() { $this->config->setLoader('File'); $this->assertTrue($this->config->load('table', true), 'Could not load config file "table".'); $tmp = $this->config->get(); $this->assertTrue(isset($tmp['obscurecode'])); $this->assertTrue(isset($tmp['user'])); $this->assertTrue(isset($tmp['usergroup'])); $this->assertTrue(isset($tmp['group'])); $tmp = $this->config->get('user'); $this->assertTrue(isset($tmp['primary'])); $tmp = $this->config->get('user/primary'); $this->assertEqual($tmp, 'uid'); } public function testLoaderConfigTable() { $this->config->setLoader('ConfigTable'); $this->assertTrue(class_exists('WBConfig_Loader_ConfigTable', false)); $this->assertFalse($this->config->load('doesnotexist', true), 'Loaded non existing config from config table'); } public function testLoaderFile() { $this->config->setLoader('File'); } public function testXInc() { $this->config->setLoader('File'); $this->config->load('user/profile/edit'); $els = $this->config->get('form/elements'); $this->assertEqual(count($els), 5); $this->assertTrue(isset($els['forename'])); $this->assertTrue(isset($els['forename']['type'])); $this->assertTrue(isset($els['forename']['attributes'])); $this->assertTrue(isset($els['lang'])); $this->assertTrue(isset($els['lang']['type'])); $this->assertTrue(isset($els['lang']['attributes'])); $this->assertEqual($els['country']['attributes']['required'], 'no'); $this->assertEqual($els['lang']['attributes']['required'], 'no'); $this->assertEqual($els['forename']['attributes']['required'], 'yes'); $this->assertEqual($els['surname']['attributes']['required'], 'yes'); } public function testMerge() { $this->config->setLoader('File'); $this->config->load('user/manager/userEdit'); $els = $this->config->get('form/elements'); $this->assertEqual(count($els), 7); $this->assertEqual($els['country']['attributes']['required'], 'no'); $this->assertEqual($els['lang']['attributes']['required'], 'no'); $this->assertEqual($els['forename']['attributes']['required'], 'no'); $this->assertEqual($els['surname']['attributes']['required'], 'no'); } }