/** * @ticket 16894 */ public function test_comment_meta_should_be_lazy_loaded_for_all_comments_in_comments_template() { global $wpdb; $p = $this->factory->post->create(array('post_status' => 'publish')); $comment_ids = $this->factory->comment->create_post_comments($p, 3); foreach ($comment_ids as $cid) { update_comment_meta($cid, 'sauce', 'fire'); } $this->go_to(get_permalink($p)); if (have_posts()) { while (have_posts()) { the_post(); // Load comments with `comments_template()`. $cform = get_echo('comments_template'); // First request will hit the database. $num_queries = $wpdb->num_queries; get_comment_meta($comment_ids[0], 'sauce'); $this->assertSame($num_queries + 1, $wpdb->num_queries); // Second and third requests should be in cache. get_comment_meta($comment_ids[1], 'sauce'); get_comment_meta($comment_ids[2], 'sauce'); $this->assertSame($num_queries + 1, $wpdb->num_queries); } } }
/** * @ticket 27246 * @ticket 35486 */ public function test_the_excerpt_password_protected_post() { $post = self::factory()->post->create_and_get(array('post_excerpt' => 'Post excerpt', 'post_password' => '1234')); $this->assertSame('There is no excerpt because this is a protected post.', get_the_excerpt($post)); $GLOBALS['post'] = $post; $this->assertSame("<p>There is no excerpt because this is a protected post.</p>\n", get_echo('the_excerpt')); }
/** * Test the different protocol references in wp_enqueue_style * @global WP_Styles $wp_styles * @ticket 16560 */ public function test_protocols() { // Init global $wp_styles; $base_url_backup = $wp_styles->base_url; $wp_styles->base_url = 'http://example.com/wordpress'; $expected = ''; $ver = get_bloginfo('version'); // Try with an HTTP reference wp_enqueue_style('reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css'); $expected .= "<link rel='stylesheet' id='reset-css-http-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver={$ver}' type='text/css' media='all' />\n"; // Try with an HTTPS reference wp_enqueue_style('reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css'); $expected .= "<link rel='stylesheet' id='reset-css-https-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver={$ver}' type='text/css' media='all' />\n"; // Try with an automatic protocol reference (//) wp_enqueue_style('reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css'); $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css' href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver={$ver}' type='text/css' media='all' />\n"; // Try with a local resource and an automatic protocol reference (//) $url = '//my_plugin/style.css'; wp_enqueue_style('plugin-style', $url); $expected .= "<link rel='stylesheet' id='plugin-style-css' href='{$url}?ver={$ver}' type='text/css' media='all' />\n"; // Try with a bad protocol wp_enqueue_style('reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css'); $expected .= "<link rel='stylesheet' id='reset-css-ftp-css' href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver={$ver}' type='text/css' media='all' />\n"; // Go! $this->assertEquals($expected, get_echo('wp_print_styles')); // No styles left to print $this->assertEquals('', get_echo('wp_print_styles')); // Cleanup $wp_styles->base_url = $base_url_backup; }
/** * Test the different protocol references in wp_enqueue_script * @global WP_Scripts $wp_scripts * @ticket 16560 */ public function test_protocols() { // Init global $wp_scripts; $base_url_backup = $wp_scripts->base_url; $wp_scripts->base_url = 'http://example.com/wordpress'; $expected = ''; $ver = get_bloginfo('version'); // Try with an HTTP reference wp_enqueue_script('jquery-http', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); $expected .= "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver={$ver}'></script>\n"; // Try with an HTTPS reference wp_enqueue_script('jquery-https', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); $expected .= "<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver={$ver}'></script>\n"; // Try with an automatic protocol reference (//) wp_enqueue_script('jquery-doubleslash', '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); $expected .= "<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver={$ver}'></script>\n"; // Try with a local resource and an automatic protocol reference (//) $url = '//my_plugin/script.js'; wp_enqueue_script('plugin-script', $url); $expected .= "<script type='text/javascript' src='{$url}?ver={$ver}'></script>\n"; // Try with a bad protocol wp_enqueue_script('jquery-ftp', 'ftp://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); $expected .= "<script type='text/javascript' src='{$wp_scripts->base_url}ftp://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver={$ver}'></script>\n"; // Go! $this->assertEquals($expected, get_echo('wp_print_scripts')); // No scripts left to print $this->assertEquals('', get_echo('wp_print_scripts')); // Cleanup $wp_scripts->base_url = $base_url_backup; }
function test_checked_publish_with_no_update_and_no_new() { update_option('webpush_triggers', array()); $admin = new WebPush_Admin(); $post = new WP_Post((object) array('post_status' => 'publish')); $box = get_echo(array($admin, 'meta_box'), array($post)); $this->assertNotContains('checked', $box); }
/** * @group 27238 */ function test_the_taxonomies_term_template() { $post_id = $this->factory->post->create(); $output = get_echo('the_taxonomies', array(array('post' => $post_id, 'term_template' => '%2$s'))); $this->assertEquals('Categories: Uncategorized.', $output); $output = get_echo('the_taxonomies', array(array('post' => $post_id, 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>'))); $link = get_category_link(1); $this->assertEquals('Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $output); }
public function test_maybe_run_ajax_cache_should_return_javascript() { $GLOBALS['post'] = $this->factory()->post->create_and_get(array('post_title' => 'Hello World')); $_GET['message'] = 'foo'; $url = admin_url('admin-ajax.php?action=oembed-cache&post=' . $GLOBALS['post']->ID, 'relative'); $actual = get_echo(array($this->wp_embed, 'maybe_run_ajax_cache')); unset($GLOBALS['post']); unset($GLOBALS['message']); $this->assertContains($url, $actual); }
/** * @ticket 27042 */ public function test_search_returns_results_for_pages() { include_once ABSPATH . 'wp-admin/includes/nav-menu.php'; self::factory()->post->create_many(3, array('post_type' => 'page', 'post_content' => 'foo')); self::factory()->post->create(array('post_type' => 'page', 'post_content' => 'bar')); $request = array('type' => 'quick-search-posttype-page', 'q' => 'foo', 'response-format' => 'json'); $output = get_echo('_wp_ajax_menu_quick_search', array($request)); $this->assertNotEmpty($output); $results = explode("\n", trim($output)); $this->assertCount(3, $results); }
function test_add_oembed_discovery_links_to_attachment() { $post_id = self::factory()->post->create(); $file = DIR_TESTDATA . '/images/canola.jpg'; $attachment_id = self::factory()->attachment->create_object($file, $post_id, array('post_mime_type' => 'image/jpeg')); $this->go_to(get_permalink($attachment_id)); $this->assertQueryTrue('is_attachment', 'is_singular', 'is_single'); $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink())) . '" />' . "\n"; $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')) . '" />' . "\n"; $this->assertEquals($expected, get_echo('wp_oembed_add_discovery_links')); }
/** * @ticket 32312 */ public function test_submit_button_and_submit_field_should_fall_back_on_defaults_when_filtered_defaults_do_not_contain_the_keys() { $p = self::factory()->post->create(); $args = array('name_submit' => 'foo-name', 'id_submit' => 'foo-id', 'class_submit' => 'foo-class', 'label_submit' => 'foo-label'); add_filter('comment_form_defaults', array($this, 'filter_comment_form_defaults')); $form = get_echo('comment_form', array($args, $p)); remove_filter('comment_form_defaults', array($this, 'filter_comment_form_defaults')); $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />'; $hidden = get_comment_id_fields($p); $this->assertRegExp('|<p class="form\\-submit">\\s*' . $button . '\\s*' . $hidden . '\\s*|', $form); }
function testDatetimeTimestampFieldAssets() { $field = new CMB_Datetime_Timestamp_Field('foo', 'Title', array()); // Register CMB-Scripts as this is a dependency. wp_enqueue_script('cmb-scripts', trailingslashit(CMB_URL) . 'js/cmb.js', array('jquery')); $field->enqueue_scripts(); $scripts_output = get_echo('wp_print_scripts'); // Scripts $this->assertContains(CMB_URL . '/js/cmb.js', $scripts_output); $this->assertContains(CMB_URL . '/js/jquery.timePicker.min.js', $scripts_output); $this->assertContains(CMB_URL . '/js/field.datetime.js', $scripts_output); }
/** * @ticket 36525 */ public function test_filtered_emoji_png_cdn() { $png_cdn = 'https://s.w.org/images/core/emoji/2.2.1/72x72/'; $svn_cdn = 'https://s.w.org/images/core/emoji/2.2.1/svg/'; $filtered_png_cdn = $this->_filtered_emoji_png_cdn(); add_filter('emoji_url', array($this, '_filtered_emoji_png_cdn')); $output = get_echo('_print_emoji_detection_script'); $this->assertContains(wp_json_encode($filtered_png_cdn), $output); $this->assertNotContains(wp_json_encode($png_cdn), $output); $this->assertContains(wp_json_encode($svn_cdn), $output); remove_filter('emoji_url', array($this, '_filtered_emoji_png_cdn')); }
/** * Test that search only returns results for published posts. * * @ticket 33742 */ public function test_search_returns_results_for_published_posts() { require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; // This will make sure that WP_Query sets is_admin to true. set_current_screen('nav-menu.php'); self::factory()->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'Publish', 'post_content' => 'FOO')); self::factory()->post->create(array('post_type' => 'post', 'post_status' => 'draft', 'post_title' => 'Draft', 'post_content' => 'FOO')); self::factory()->post->create(array('post_type' => 'post', 'post_status' => 'pending', 'post_title' => 'Pending', 'post_content' => 'FOO')); self::factory()->post->create(array('post_type' => 'post', 'post_status' => 'future', 'post_title' => 'Future', 'post_content' => 'FOO', 'post_date' => gmdate('Y-m-d H:i:s', strtotime('+1 month')))); $request = array('type' => 'quick-search-posttype-post', 'q' => 'FOO'); $output = get_echo('_wp_ajax_menu_quick_search', array($request)); $this->assertNotEmpty($output); $results = explode("\n", trim($output)); $this->assertCount(1, $results); }
public function test_custom_submit_field() { $p = $this->factory->post->create(); $args = array( 'name_submit' => 'foo-name', 'id_submit' => 'foo-id', 'class_submit' => 'foo-class', 'label_submit' => 'foo-label', 'submit_field' => '<p class="my-custom-submit-field">%1$s %2$s</p>' ); $form = get_echo( 'comment_form', array( $args, $p ) ); $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />'; $hidden = get_comment_id_fields( $p ); $this->assertRegExp( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form ); }
function test_rest_pre_serve_request_headers() { if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('xdebug is required for this test'); } $post = $this->factory()->post->create_and_get(array('post_title' => 'Hello World')); $request = new WP_REST_Request('GET', '/oembed/1.0/embed'); $request->set_param('url', get_permalink($post->ID)); $request->set_param('format', 'xml'); $server = new WP_REST_Server(); $response = $server->dispatch($request); $output = get_echo('_oembed_rest_pre_serve_request', array(true, $response, $request, $server)); $this->assertNotEmpty($output); $headers = xdebug_get_headers(); $this->assertTrue(in_array('Content-Type: text/xml; charset=' . get_option('blog_charset'), $headers)); }
/** * @ticket 24330 * * setup_postdata( $a_post ) followed by the_content() in a loop that does not update * global $post should use the content of $a_post rather then the global post. */ function test_setup_postdata_loop() { $post_id = $this->factory->post->create( array( 'post_content' => 'global post' ) ); $GLOBALS['wp_query']->post = $GLOBALS['post'] = get_post( $post_id ); $ids = $this->factory->post->create_many(5); foreach ( $ids as $id ) { $page = get_post( $id ); if ( $page ) { setup_postdata( $page ); $content = get_echo( 'the_content', array() ); $this->assertEquals( $post_id, $GLOBALS['post']->ID ); $this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) ); wp_reset_postdata(); } } }
/** * @ticket 35175 */ public function test_should_respect_reverse_top_level_param() { $p = self::factory()->post->create(); $comments = array(); $now = time(); for ($i = 0; $i <= 5; $i++) { $comments[] = self::factory()->comment->create(array('comment_post_ID' => $p, 'comment_date_gmt' => date('Y-m-d H:i:s', $now - $i), 'comment_author' => 'Commenter ' . $i)); } update_option('page_comments', true); update_option('comments_per_page', 2); $this->go_to(get_permalink($p)); // comments_template() populates $wp_query->comments get_echo('comments_template'); $found1 = wp_list_comments(array('reverse_top_level' => true, 'echo' => false)); preg_match_all('|id="comment\\-([0-9]+)"|', $found1, $matches); $this->assertSame(array($comments[0], $comments[1]), array_map('intval', $matches[1])); $found2 = wp_list_comments(array('reverse_top_level' => false, 'echo' => false)); preg_match_all('|id="comment\\-([0-9]+)"|', $found2, $matches); $this->assertSame(array($comments[1], $comments[0]), array_map('intval', $matches[1])); }
/** * @ticket 37048 */ public function test_custom_pagination_should_allow_ones_own_unapproved_comments() { $p = self::factory()->post->create(); $u = self::factory()->user->create(); $comments = array(); $now = time(); for ($i = 0; $i <= 5; $i++) { $comments[] = self::factory()->comment->create(array('comment_post_ID' => $p, 'comment_date_gmt' => date('Y-m-d H:i:s', $now - $i), 'comment_author' => 'Commenter ' . $i, 'user_id' => $u)); } // Only 2 and 5 are approved. wp_set_comment_status($comments[0], '0'); wp_set_comment_status($comments[1], '0'); wp_set_comment_status($comments[3], '0'); wp_set_comment_status($comments[4], '0'); update_option('page_comments', true); update_option('comments_per_page', 2); wp_set_current_user($u); $this->go_to(get_permalink($p)); // comments_template() populates $wp_query->comments get_echo('comments_template'); $found = wp_list_comments(array('echo' => false, 'per_page' => 1, 'page' => 2)); preg_match_all('|id="comment\\-([0-9]+)"|', $found, $matches); $this->assertSame(array($comments[4]), array_map('intval', $matches[1])); }
function test_generate_manifest_link() { $this->assertEquals('<link rel="manifest" href="http://example.org/wp-content/uploads/wpservefile_files/manifest.json">', get_echo(array(Mozilla\WebAppManifestGenerator::getInstance(), 'add_manifest'))); }
function test_gallery_attributes() { // make sure the gallery shortcode attributes are parsed correctly $id = 575; $post = get_post($id); $this->assertNotNull($post, "get_post({$id}) could not find the post."); $post->post_content = '[gallery columns="1" size="medium"]'; wp_update_post($post); // permalink page $this->go_to('/2008/04/01/simple-gallery-test/'); the_post(); // filtered output $out = get_echo('the_content'); $expected = <<<EOF \t\t<style type='text/css'> \t\t\t.gallery { \t\t\t\tmargin: auto; \t\t\t} \t\t\t.gallery-item { \t\t\t\tfloat: left; \t\t\t\tmargin-top: 10px; \t\t\t\ttext-align: center; \t\t\t\twidth: 100%;\t\t\t} \t\t\t.gallery img { \t\t\t\tborder: 2px solid #cfcfcf; \t\t\t} \t\t\t.gallery-caption { \t\t\t\tmargin-left: 0; \t\t\t} \t\t</style> \t\t<!-- see gallery_shortcode() in wp-includes/media.php --> \t\t<div class='gallery'><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=565' title='dsc20040724_152504_53'><img src="http://example.com/wp-content/uploads/2008/04/dsc20040724_152504_537.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=566' title='canola'><img src="http://example.com/wp-content/uploads/2008/04/canola3.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=567' title='dsc20050315_145007_13'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050315_145007_134.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=568' title='dsc20050604_133440_34'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050604_133440_343.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=569' title='dsc20050831_165238_33'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050831_165238_333.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=570' title='dsc20050901_105100_21'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050901_105100_213.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=571' title='dsc20050813_115856_5'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050813_115856_54.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=572' title='dsc20050720_123726_27'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050720_123726_274.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=573' title='Title: Seedlings'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050727_091048_224.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /><dl class='gallery-item'> \t\t\t<dt class='gallery-icon'> \t\t\t\t<a href='http://example.com/?attachment_id=574' title='dsc20050726_083116_18'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050726_083116_184.jpg" class="attachment-medium" alt="" /></a> \t\t\t</dt></dl><br style="clear: both" /> \t\t\t<br style='clear: both;' /> \t\t</div> EOF; $this->assertEquals(strip_ws($expected), strip_ws($out)); }
/** * @ticket 14853 */ public function test_wp_add_inline_script_concat_with_conditional() { global $wp_scripts; $wp_scripts->do_concat = true; $wp_scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); // Default dirs as in wp-includes/script-loader.php $expected_localized = "<!--[if gte IE 9]>\n"; $expected_localized .= "<script type='text/javascript'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n"; $expected_localized .= "<![endif]-->\n"; $expected = "<!--[if gte IE 9]>\n"; $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; $expected .= "<![endif]-->\n"; wp_enqueue_script('test-example', 'example.com', array(), null); wp_localize_script('test-example', 'testExample', array('foo' => 'bar')); wp_add_inline_script('test-example', 'console.log("before");', 'before'); wp_add_inline_script('test-example', 'console.log("after");'); wp_script_add_data('test-example', 'conditional', 'gte IE 9'); $this->assertEquals($expected_localized, get_echo('wp_print_scripts')); $this->assertEquals($expected, $wp_scripts->print_html_before); $this->assertEquals('', $wp_scripts->print_html); }
/** * @ticket 32495 * * @dataProvider data_admin_bar_nodes_with_tabindex_meta * * @param array $node_data The data for a node, passed to `WP_Admin_Bar::add_node()`. * @param string $expected_html The expected HTML when admin menu is rendered. */ public function test_admin_bar_with_tabindex_meta($node_data, $expected_html) { $admin_bar = new WP_Admin_Bar(); $admin_bar->add_node($node_data); $admin_bar_html = get_echo(array($admin_bar, 'render')); $this->assertContains($expected_html, $admin_bar_html); }
/** * @ticket 22229 */ function test_inline_should_not_output_script_tag_with_src() { wp_enqueue_script( 'baba-inline-0', 'inline' ); $this->assertEquals( '', get_echo( 'wp_print_scripts' ) ); }
/** * @author georgestephanis * @covers Jetpack::dns_prefetch * @since 3.3.0 */ public function test_dns_prefetch() { // Purge it for a clean start. ob_start(); Jetpack::dns_prefetch(); ob_end_clean(); Jetpack::dns_prefetch('http://example1.com/'); Jetpack::dns_prefetch(array('http://example2.com/', 'https://example3.com')); Jetpack::dns_prefetch('https://example2.com'); $expected = "\r\n" . "<link rel='dns-prefetch' href='//example1.com'>\r\n" . "<link rel='dns-prefetch' href='//example2.com'>\r\n" . "<link rel='dns-prefetch' href='//example3.com'>\r\n"; $this->assertEquals($expected, get_echo(array('Jetpack', 'dns_prefetch'))); }
function test_rest_pre_serve_request() { $user = $this->factory()->user->create_and_get(array('display_name' => 'John Doe')); $post = $this->factory()->post->create_and_get(array('post_author' => $user->ID, 'post_title' => 'Hello World')); $request = new WP_REST_Request('GET', '/oembed/1.0/embed'); $request->set_param('url', get_permalink($post->ID)); $request->set_param('format', 'xml'); $response = $this->server->dispatch($request); $output = get_echo('_oembed_rest_pre_serve_request', array(true, $response, $request, $this->server)); $xml = simplexml_load_string($output); $this->assertInstanceOf('SimpleXMLElement', $xml); }
function test_thematic_override_tag_loop() { $this->assertEquals('override tag loop!', get_echo('thematic_tagloop')); }
/** * Test to make sure that inline styles attached to conditional * stylesheets are also conditional. */ public function test_conditional_inline_styles_are_also_conditional() { $expected = <<<CSS <!--[if IE]> <link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' /> <style id='handle-inline-css' type='text/css'> a { color: blue; } </style> <![endif]--> CSS; wp_enqueue_style('handle', 'http://example.com', array(), 1); wp_style_add_data('handle', 'conditional', 'IE'); wp_add_inline_style('handle', 'a { color: blue; }'); $this->assertEquals($expected, get_echo('wp_print_styles')); }
/** * @ticket 37502 */ function test_deregistered_scripts_are_ignored() { $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n"; wp_enqueue_script('test-script', 'http://example.org/script.js'); wp_deregister_script('test-script'); $actual = get_echo('wp_resource_hints'); $this->assertEquals($expected, $actual); }
/** * Test to make sure <style> tags aren't output if there are no inline styles. * @ticket 24813 */ public function test_unnecessary_style_tags() { $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); }
function test_adding_tutorial_text_to_single() { //creating admin user and set ut $user = new WP_User($this->factory->user->create(array('role' => 'administrator'))); wp_set_current_user($user->ID); //create category $cat_id = $this->factory->category->create(array('slug' => rand_str(), 'name' => rand_str(), 'description' => rand_str())); //create 3 posts, the $post_ids[1] is the middle one, suppose to have next and prev in the pretext $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST1', 'post_date' => date('Y-m-d H:i:s', time() - 300))); $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST2', 'post_date' => date('Y-m-d H:i:s', time() - 200))); $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST3', 'post_date' => date('Y-m-d H:i:s', time() - 100))); //adding them to the category foreach ($post_ids as $post_id) { $res = wp_set_post_categories($post_id, $cat_id); } //making the category a tutorial category $this->auxClass->set_up_post_data(); $this->plugin_admin->wp_tutorial_maker_option_update($cat_id); //go to tutorial post $this->go_to(get_permalink($post_ids[1])); $post_content_inside_tutorial = get_echo('the_content'); //making sure that the tutorial pretext that I want is there $this->assertRegExp('/<div class=\'wptm_prev\'><span>Some prev text<\\/span><a href="http:\\/\\/example\\.org\\/\\?p=' . $post_ids[0] . '" rel="prev">POST1<\\/a> <\\/div>/', $post_content_inside_tutorial); $this->assertRegExp('/<div class=\'wptm_next\'><span>Some next text<\\/span><a href="http:\\/\\/example\\.org\\/\\?p=' . $post_ids[2] . '" rel="next">POST3<\\/a> <\\/div>/', $post_content_inside_tutorial); $this->assertRegExp('/<div id=\'wptm_before_category_link_text\'>Some Category List Header<\\/div>/', $post_content_inside_tutorial); $this->assertRegExp('/<div id=\'wptm_before_category_link_text\'>Some Category List Header<\\/div>/', $post_content_inside_tutorial); $this->assertRegExp('/<div class=\'wptm_link_to_category\'><a href=\'http:\\/\\/example\\.org\\/\\?cat=' . $cat_id . '\'>Some Name to Category Link<\\/div>/', $post_content_inside_tutorial); //making sure that the tutorial pretext is not being added by mistake to some other non Tutorial post $non_tutorial_post_id = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST2', 'post_date' => date('Y-m-d H:i:s', time() - 200))); $this->go_to(get_permalink($non_tutorial_post_id)); $post_content_inside_tutorial = get_echo('the_content'); $this->assertNotRegExp('/wptm/', $post_content_inside_tutorial); }