function testCheckedOptions() { $this->diw->display_options = array_keys($this->diw->_valid_options); ob_start(); $this->diw->render_ui(); $result = ob_get_clean(); $this->assertTrue(($xml = _to_xml($result, true)) !== false); foreach ($this->diw->display_options as $option) { $this->assertTrue(_node_exists($xml, '//input[@name="hubblesite[' . $option . ']" and @checked="checked"]')); } }
function testGenerateAdditionalCategoriesCheckboxes() { global $comicpress_manager; $comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option')); $comicpress_manager->properties['blogcat'] = 1; $this->v->category_tree = array('0/2'); $comicpress_manager->expects($this->once())->method('get_cpm_option')->will($this->returnValue("4")); add_category(3, (object) array('cat_name' => 'Test', 'parent' => 0)); add_category(4, (object) array('cat_name' => 'Test 2', 'parent' => 0)); $result = $this->v->_generate_additional_categories_checkboxes(); $this->assertTrue(count($result) == 2); $this->assertTrue(count($this->v->category_checkboxes) == 2); $this->assertTrue(($first = _to_xml($result[0])) !== false); $this->assertTrue(_node_exists($first, '//label/input[@value="3" and not(@checked="checked")]')); $this->assertTrue(($second = _to_xml($result[1])) !== false); $this->assertTrue(_node_exists($second, '//label/input[@value="4" and @checked="checked"]')); }
function testHandleWarnings() { global $comicpress_manager; foreach (array('messages', 'warnings') as $type) { $comicpress_manager = (object) array($type => array('test'), 'show_config_editor' => false); ob_start(); $this->assertTrue($this->adm->handle_warnings()); $result = ob_get_clean(); $this->assertTrue(!empty($result), $type); $this->assertTrue(($xml = _to_xml($result)) !== false); $this->assertTrue(_node_exists($xml, '//div[@id="cpm-' . $type . '"]')); $this->assertFalse(strpos($result, "You won't be able") !== false); $this->assertFalse(strpos($result, "Debug info") !== false); } $adm = $this->getMock('ComicPressManagerAdmin', array('edit_config', 'get_backup_files')); $adm->expects($this->any())->method('edit_config'); $adm->expects($this->any())->method('get_backup_files')->will($this->returnValue(array())); $comicpress_manager = $this->getMock('ComicPressManager', array('get_subcomic_directory')); $comicpress_manager->errors = array('test'); $comicpress_manager->show_config_editor = false; $comicpress_manager->config_method = ""; ob_start(); $this->assertFalse($adm->handle_warnings()); $result = ob_get_clean(); $this->assertTrue(strpos($result, "You won't be able") !== false); $this->assertTrue(strpos($result, "Debug info") !== false); $comicpress_manager = $this->getMock('ComicPressManager', array('get_subcomic_directory')); $comicpress_manager->errors = array('test'); $comicpress_manager->show_config_editor = true; $comicpress_manager->config_method = ""; add_category(1, (object) array('name' => 'Test')); ob_start(); $this->assertFalse($adm->handle_warnings()); $result = ob_get_clean(); $this->assertTrue(strpos($result, "You won't be able") !== false); $this->assertTrue(strpos($result, "<td>Test</td>") !== false); $this->assertTrue(strpos($result, '<td align="center">1</td>') !== false); $adm = $this->getMock('ComicPressManagerAdmin', array('edit_config', 'get_backup_files')); $adm->expects($this->never())->method('edit_config'); $adm->expects($this->once())->method('get_backup_files')->will($this->returnValue(array('12345'))); $comicpress_manager = $this->getMock('ComicPressManager', array('get_subcomic_directory')); $comicpress_manager->errors = array('test'); $comicpress_manager->show_config_editor = false; $comicpress_manager->can_write_config = true; $comicpress_manager->config_method = "comicpress-config.php"; ob_start(); $this->assertFalse($adm->handle_warnings()); $result = ob_get_clean(); $this->assertFalse(strpos($result, "You won't be able") !== false); $this->assertTrue(strpos($result, "Some backup") !== false); $this->assertTrue(strpos($result, '<option value="12345">') !== false); $this->assertTrue(strpos($result, "Debug info") !== false); }
/** * Test a SimpleXMLElement node for the provided XPath. * @param SimpleXMLElement $xml The node to check. * @param string $xpath The XPath to search for. * @param mixed $value Either a string that the XPath's value should match, true if the node simply needs to exist, or false if the node shouldn't exist. * @return boolen True if the XPath matches. */ function _xpath_test($xml, $xpath, $value) { if ($value === true) { $value = "~*exists*~"; } if ($value === false) { $value = "~*not exists*~"; } switch ($value) { case "~*exists*~": return _node_exists($xml, $xpath); break; case "~*not exists*~": return !_node_exists($xml, $xpath); break; default: return _get_node_value($xml, $xpath) == $value; } return false; }