function testCreateDimensionSelector() { $source = $this->core->create_dimension_selector("test", "760x340"); $this->assertTrue(($xml = _to_xml($source, true)) !== false); foreach (array('//input[@name="test[width]" and @value="760"]' => true, '//input[@name="test[height]" and @value="340"]' => true) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
function testWidgetErrors() { global $comicpress_manager, $comicpress_manager_admin; $comicpress_manager = $this->getMock('ComicPressManager'); $comicpress_manager->expects($this->once())->method('get_subcomic_directory')->will($this->returnValue(false)); $comicpress_manager->errors = array('test'); $w = new ComicPressQuomicPressWidget(); $this->assertFalse($w->show_widget); $this->assertTrue(empty($w->thumbnails_to_generate)); $comicpress_manager_admin = new ComicPressManagerAdmin(); ob_start(); $w->render(); $this->assertTrue(($xml = _to_xml(ob_get_clean())) !== false); }
/** * @dataProvider providerTestWidget */ function testWidget($instance, $expected_xpath, $is_home = false) { global $post; $post = (object) array('ID' => 1, 'guid' => 'Post url'); wp_insert_post($post); $w = new ComicPressBookmarkWidget(); _set_bloginfo('url', 'Blog url'); _set_current_option('is_home', $is_home); ob_start(); $w->widget(array('before_widget' => '', 'after_widget' => '', 'before_title' => '<p>', 'after_title' => '</p>'), $instance); $content = ob_get_clean(); $this->assertTrue(($xml = _to_xml($content, true)) !== false); foreach ($expected_xpath as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
function testRenderGenerationStates() { global $comicpress_manager, $comicpress_manager_admin; add_category(1, (object) array('name' => 'Comics')); add_category(2, (object) array('name' => 'Blog')); $s = new ComicPressSidebarStandard(); $s->thumbnail_generation = array('rss' => true, 'archive' => array("test")); $comicpress_manager_admin = $this->getMock('ComicPressManagerAdmin', array('show_debug_info')); ob_start(); $s->render(); $source = ob_get_clean(); $this->assertTrue(($xml = _to_xml($source, true)) !== false); foreach (array() as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } $this->markTestIncomplete(); }
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 testRenderPre28WidgetControl() { update_option('plugin-wonderful-pre28-widget-info', array('adboxid' => 123, 'center' => 1)); $this->pw->publisher_info->adboxes = array((object) array('adboxid' => '123')); ob_start(); $this->pw->render_pre28_widget_control(); $source = ob_get_clean(); $this->assertTrue(($xml = _to_xml($source)) !== false); foreach (array('//input[@name="_pw_nonce"]' => true, '//input[@name="pw[adboxid]"]' => true, '//input[@name="pw[center]"]' => true) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
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); }
function testObfuscateFilenames() { global $comicpress_manager; $comicpress_manager = $this->getMock('ComicPressManager', array('get_subcomic_directory', 'get_cpm_option')); $comicpress_manager->expects($this->any())->method('get_subcomic_directory')->will($this->returnValue(false)); $comicpress_manager->expects($this->at(1))->method('get_cpm_option')->with('cpm-obfuscate-filenames-on-upload')->will($this->returnValue("test")); ob_start(); $this->u->render(); $result = ob_get_clean(); $this->assertTrue(($xml = _to_xml($result)) !== false); foreach (array('//h3[contains(text(), "uploaded filenames will be obfuscated")]' => true) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
function testDisplayMessages() { $this->admin->info('info'); $this->admin->warn('warn'); $this->admin->error('error'); ob_start(); $this->admin->display_messages(); $this->assertTrue(($xml = _to_xml(ob_get_clean())) !== false); foreach (array('//div[contains(@class, "cp-info")]/p' => 'info', '//div[contains(@class, "cp-warn")]/p' => 'warn', '//div[contains(@class, "cp-error")]/p' => 'error') as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
function testInstructions() { global $plugin_wonderful; $plugin_wonderful->publisher_info = true; $this->m->_pw_nonce = "345"; $this->m->first_adboxid = "123"; $_GET['allow-destroy'] = 1; ob_start(); $this->m->_render_instructions(); $source = ob_get_clean(); $this->assertTrue(!empty($source)); $this->assertTrue(($xml = _to_xml($source, true)) !== false); foreach (array('//tt[contains(text(), "the_project_wonderful_ad(123)")]' => true, '//tt[contains(text(), "PW(123)")]' => true, '//tt[contains(text(), "PW\\(123\\)")]' => true, '//form[@id="allow-destroy-handler"]/input[@name="_pw_nonce" and @value="345"]' => true, '//form[@id="allow-destroy-handler"]/input[@name="_pw_action" and @value="rebuild-database"]' => true) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }
function testWidgetUI() { ob_start(); $this->diw->render_ui(); $result = ob_get_clean(); $this->assertTrue(!empty($result)); $this->assertTrue(($xml = _to_xml($result, true)) !== false); foreach ($this->diw->_valid_options as $option => $label) { $xpath = "//label[contains(text(), '{$label}')]"; $this->assertTrue(_xpath_test($xml, $xpath, true), $xpath); } foreach (array('//input[@type="hidden" and @name="hubblesite[_wpnonce]"]' => true) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } }