function test_strip_ws() { $this->assertEquals('', strip_ws('')); $this->assertEquals('foo', strip_ws('foo')); $this->assertEquals('', strip_ws("\r\n\t \n\r\t")); $in = "asdf\n"; $in .= "asdf asdf\n"; $in .= "asdf asdf\n"; $in .= "\tasdf\n"; $in .= "\tasdf\t\n"; $in .= "\t\tasdf\n"; $in .= "foo bar\n\r\n"; $in .= "foo\n"; $expected = "asdf\n"; $expected .= "asdf asdf\n"; $expected .= "asdf asdf\n"; $expected .= "asdf\n"; $expected .= "asdf\n"; $expected .= "asdf\n"; $expected .= "foo bar\n"; $expected .= "foo"; $this->assertEquals($expected, strip_ws($in)); }
/** * @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(); } } }
function test_the_content_attribute_value_with_colon() { kses_init_filters(); // http://bpr3.org/?p=87 // the title attribute should make it through unfiltered $post_content = <<<EOF <span title="My friends: Alice, Bob and Carol">foo</span> EOF; $expected = <<<EOF <p><span title="My friends: Alice, Bob and Carol">foo</span></p> EOF; $post_id = self::factory()->post->create(compact('post_content')); $this->go_to(get_permalink($post_id)); $this->assertTrue(is_single()); $this->assertTrue(have_posts()); $this->assertNull(the_post()); $this->assertEquals(strip_ws($expected), strip_ws(get_echo('the_content'))); kses_remove_filters(); }
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)); }
function test_mixed_tags() { $in = <<<EOF So this is a post with [footag foo="some stuff"] and a bunch of tags. [bartag] [baztag] Here's some content on more than one line [/baztag] [bartag foo=1] [baztag] [footag foo="2"] [baztag] [baztag] more content [/baztag] EOF; $expected = <<<EOF So this is a post with foo = some stuff and a bunch of tags. foo = no foo content = Here's some content on more than one line foo = 1 content = foo = 2 content = content = more content EOF; $out = do_shortcode($in); $this->assertEquals(strip_ws($expected), strip_ws($out)); }
function test_post_additional_content_shortcode() { $blob = <<<BLOB Post content [shortcode_content] BLOB; $meta = $this->utils->additional1; $post_id_1 = $this->factory->post->create(array('post_content' => $blob)); $post_id_2 = $this->factory->post->create(array('post_content' => 'Post content')); $meta = $this->utils->additional1; $meta['priority'] = 10; $meta['additional_content'] = '[shortcode_content]'; update_post_meta($post_id_2, '_ac_additional_content', array($meta)); // Go to the the single post 1 page. $this->go_to(get_permalink($post_id_1)); // Get the post content. ob_start(); the_post(); the_content(); $content_1 = ob_get_clean(); rewind_posts(); // Go to the the single post 2 page. $this->go_to(get_permalink($post_id_2)); // Get the post content. ob_start(); the_post(); the_content(); $content_2 = ob_get_clean(); $this->assertEquals(strip_ws($content_1), strip_ws($content_2)); }