"variables-empty.yml", "testVariable_getNewWayString" => "variables-empty.yml", "testVariable_getOldWay" => "variables-empty.yml", "default" => "variables.yml" ); if (isset($list[$this->getName()])) { $dataset_file = $list[$this->getName()]; } else { $dataset_file = "variables.yml"; } return parent::loadDataSet($dataset_file); } /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); $this->object = new m_variables; } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { parent::tearDown(); } /** * @covers m_variables::variable_init * @depends testGet_impersonated */ public function testVariable_init($variables) { $this->object->variable_init(); global $conf; $this->assertTrue(is_array($conf)); } /** * @covers m_variables::get_impersonated */ public function testGet_impersonated() { $variables = $this->object->get_impersonated(); return $variables; } /** * @covers m_variables::variable_init_maybe */ public function testVariable_init_maybe() { $this->object->variable_init_maybe(); $this->assertTrue( (is_array($this->object->cache_conf) && !empty($this->object->cache_conf)) ); } /** * @covers m_variables::variable_get */ public function testVariable_get() { $result = $this->object->variable_get("phpunit"); $this->assertStringMatchesFormat("phpunit",$result); } /** * @covers m_variables::variable_get */ public function testVariable_getOldWay() { $this->object->variable_get('phpunit', 'phpunit-default','phpunit-comment'); $result = $this->object->variable_get('phpunit'); $this->assertSame("phpunit-default",$result); } /** * @covers m_variables::variable_get */ public function testVariable_getNewWayString() { // New way $this->object->variable_get('phpunit', 'phpunit-default','comment', array('desc'=>'Want a string','type'=>'string')); $result = $this->object->variable_get('phpunit'); $this->assertSame("phpunit-default",$result); } /** * @covers m_variables::variable_get */ public function testVariable_getNewWayArray() { $phpunitArray = array("ns1"=>'ns1.tld',"ip"=>"1.2.3.4"); $this->object->variable_get('phpunit', $phpunitArray,'phpunit-comment', array("ns1"=>array('desc'=>'ns name','type'=>'string'),"ip"=>array("desc"=>"here an ip", "type"=>"ip"))); $result = $this->object->variable_get('phpunit'); $this->assertSame($phpunitArray,$result); } /** * @covers m_variables::variable_update_or_create * @expectedException \Exception */ public function testVariable_create_exception() { // Insert key with already existing key : success $result = $this->object->variable_update_or_create("phpunit","phpunit-fail","DEFAULT",0); } /** * @covers m_variables::variable_update_or_create */ public function testVariable_create() { // Insert key with new key : success $result = $this->object->variable_update_or_create("phpunit-success","phpunit","DEFAULT",0); $this->assertTrue($result); $this->assertEquals(2, $this->getConnection()->getRowCount('variable')); } /** * @covers m_variables::variable_update_or_create */ public function testVariable_update() { $result = $this->object->variable_update_or_create("phpunit","phpunit-updated","DEFAULT",0,999); $this->assertTrue($result); $this->assertEquals(1, $this->getConnection()->getRowCount('variable')); $expectedTable = $this->loadDataSet("variables-updated.yml")->getTable("variable"); $currentTable = $this->getConnection()->createQueryTable('variable', 'SELECT * FROM variable'); $this->assertTablesEqual($expectedTable, $currentTable); } /** * @covers m_variables::del */ public function testDel() { $result = $this->object->del(999); $this->assertTrue($result); $this->assertEquals(0, $this->getConnection()->getRowCount('variable')); } /** * @covers m_variables::display_valueraw_html */ public function testDisplay_valueraw_html() { // Empty string $empty_result = $this->object->display_valueraw_html(null, "phpunit",FALSE); $this->assertStringMatchesFormat(""._("Empty")."",$empty_result); // Empty array $empty_array_result = $this->object->display_valueraw_html(array(), "phpunit",FALSE); $this->assertStringMatchesFormat(""._("Empty array")."",$empty_array_result); // String $value_result = $this->object->display_valueraw_html("value", "phpunit",FALSE); $this->assertStringMatchesFormat($value_result,$value_result); // String $array_result = $this->object->display_valueraw_html(array("value","value"), "phpunit",FALSE); $this->assertStringMatchesFormat("