123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- // save and fetch posts to make sure content is properly filtered.
- // these tests don't care what code is responsible for filtering or how it is called, just that it happens when a post is saved.
- /**
- * @group post
- * @group formatting
- */
- class Tests_Post_Filtering extends WP_UnitTestCase {
- function setUp() {
- parent::setUp();
- update_option('use_balanceTags', 1);
- kses_init_filters();
- }
- function tearDown() {
- kses_remove_filters();
- parent::tearDown();
- }
- // a simple test to make sure unclosed tags are fixed
- function test_post_content_unknown_tag() {
- $content = <<<EOF
- <foobar>no such tag</foobar>
- EOF;
- $expected = <<<EOF
- no such tag
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- // a simple test to make sure unbalanced tags are fixed
- function test_post_content_unbalanced_tag() {
- $content = <<<EOF
- <i>italics
- EOF;
- $expected = <<<EOF
- <i>italics</i>
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- // test kses filtering of disallowed attribute
- function test_post_content_disallowed_attr() {
- $content = <<<EOF
- <img src='foo' width='500' href='shlorp' />
- EOF;
- $expected = <<<EOF
- <img src='foo' width='500' />
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- /**
- * test kses bug. xhtml does not require space before closing empty element
- * @ticket 12394
- */
- function test_post_content_xhtml_empty_elem() {
- $content = <<<EOF
- <img src='foo' width='500' height='300'/>
- EOF;
- $expected = <<<EOF
- <img src='foo' width='500' height='300' />
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- /**
- * make sure unbalanced tags are fixed when they span a --more-- tag
- * @ticket 6297
- */
- function test_post_content_unbalanced_more() {
- $content = <<<EOF
- <em>some text<!--more-->
- that's continued after the jump</em>
- EOF;
- $expected = <<<EOF
- <em>some text</em><!--more-->
- that's continued after the jump
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- /**
- * make sure unbalanced tags are fixed when they span a --nextpage-- tag
- * @ticket 6297
- */
- function test_post_content_unbalanced_nextpage() {
- $content = <<<EOF
- <em>some text<!--nextpage-->
- that's continued after the jump</em>
- EOF;
- $expected = <<<EOF
- <em>some text</em><!--nextpage-->
- that's continued after the jump
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- /**
- * make sure unbalanced tags are fixed when they span both --more-- and --nextpage-- tags (in that order)
- * @ticket 6297
- */
- function test_post_content_unbalanced_more_nextpage() {
- $content = <<<EOF
- <em>some text<!--more-->
- that's continued after the jump</em>
- <!--nextpage-->
- <p>and the next page
- <!--nextpage-->
- breaks the graf</p>
- EOF;
- $expected = <<<EOF
- <em>some text</em><!--more-->
- that's continued after the jump
- <!--nextpage-->
- <p>and the next page
- </p><!--nextpage-->
- breaks the graf
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- /**
- * make sure unbalanced tags are fixed when they span both --nextpage-- and --more-- tags (in that order)
- * @ticket 6297
- */
- function test_post_content_unbalanced_nextpage_more() {
- $content = <<<EOF
- <em>some text<!--nextpage-->
- that's continued after the jump</em>
- <!--more-->
- <p>and the next page
- <!--nextpage-->
- breaks the graf</p>
- EOF;
- $expected = <<<EOF
- <em>some text</em><!--nextpage-->
- that's continued after the jump
- <!--more-->
- <p>and the next page
- </p><!--nextpage-->
- breaks the graf
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $expected, $post->post_content );
- }
- // make sure unbalanced tags are untouched when the balance option is off
- function test_post_content_nobalance_nextpage_more() {
- update_option('use_balanceTags', 0);
- $content = <<<EOF
- <em>some text<!--nextpage-->
- that's continued after the jump</em>
- <!--more-->
- <p>and the next page
- <!--nextpage-->
- breaks the graf</p>
- EOF;
- $id = $this->factory->post->create( array( 'post_content' => $content ) );
- $post = get_post($id);
- $this->assertEquals( $content, $post->post_content );
- }
- }
|