| | 1 | <?php |
| | 2 | /** |
| | 3 | * @group formatting |
| | 4 | */ |
| | 5 | class Tests_Formatting_FillEmptyLinks extends WP_UnitTestCase { |
| | 6 | |
| | 7 | /** |
| | 8 | * @ticket 12480 |
| | 9 | */ |
| | 10 | public function test_content_with_link() { |
| | 11 | $content = 'This <a href="http://example.com"></a>is a link'; |
| | 12 | |
| | 13 | $this->assertEquals( |
| | 14 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 15 | fill_empty_links( $content ) |
| | 16 | ); |
| | 17 | } |
| | 18 | |
| | 19 | /** |
| | 20 | * @ticket 12480 |
| | 21 | */ |
| | 22 | public function test_content_with_multiple_links() { |
| | 23 | $content = 'This <a href="http://example.com"></a>is a link <a href="http://example.com/test"></a>'; |
| | 24 | |
| | 25 | $this->assertEquals( |
| | 26 | 'This <a href="http://example.com">http://example.com</a>is a link <a href="http://example.com/test">http://example.com/test</a>', |
| | 27 | fill_empty_links( $content ) |
| | 28 | ); |
| | 29 | } |
| | 30 | |
| | 31 | /** |
| | 32 | * Sanity check: verify we're not changing things when links aren't present. |
| | 33 | * |
| | 34 | * @ticket 12480 |
| | 35 | */ |
| | 36 | public function test_content_without_links() { |
| | 37 | $content = 'Lorem ipsum sit dolor'; |
| | 38 | |
| | 39 | $this->assertEquals( $content, fill_empty_links( $content ) ); |
| | 40 | } |
| | 41 | |
| | 42 | /** |
| | 43 | * @ticket 12480 |
| | 44 | */ |
| | 45 | public function test_content_with_whitespace() { |
| | 46 | $this->assertEquals( |
| | 47 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 48 | fill_empty_links( 'This <a href="http://example.com"> </a>is a link' ), |
| | 49 | 'fill_empty_links() fails to match regular whitespace' |
| | 50 | ); |
| | 51 | |
| | 52 | $this->assertEquals( |
| | 53 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 54 | fill_empty_links( 'This <a href="http://example.com"> </a>is a link' ), |
| | 55 | 'fill_empty_links() fails to match regular whitespaces' |
| | 56 | ); |
| | 57 | |
| | 58 | $this->assertEquals( |
| | 59 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 60 | fill_empty_links( 'This <a href="http://example.com"> </a>is a link' ), |
| | 61 | 'fill_empty_links() fails to match non-breaking whitespace' |
| | 62 | ); |
| | 63 | |
| | 64 | $this->assertEquals( |
| | 65 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 66 | fill_empty_links( 'This <a href="http://example.com">‍</a>is a link' ), |
| | 67 | 'fill_empty_links() fails to match zero-width joiner' |
| | 68 | ); |
| | 69 | |
| | 70 | $this->assertEquals( |
| | 71 | 'This <a href="http://example.com">http://example.com</a>is a link', |
| | 72 | fill_empty_links( 'This <a href="http://example.com">‌</a>is a link' ), |
| | 73 | 'fill_empty_links() fails to match zero-width non-joiner' |
| | 74 | ); |
| | 75 | } |
| | 76 | |
| | 77 | /** |
| | 78 | * @ticket 12480 |
| | 79 | */ |
| | 80 | public function test__fill_empty_links() { |
| | 81 | $matches = array( |
| | 82 | '0' => 'This <a href="http://example.com"></a>is a link', |
| | 83 | '1' => 'http://example.com', |
| | 84 | ); |
| | 85 | |
| | 86 | $this->assertEquals( |
| | 87 | '<a href="http://example.com">http://example.com</a>', |
| | 88 | _fill_empty_links( $matches ) |
| | 89 | ); |
| | 90 | } |
| | 91 | |
| | 92 | /** |
| | 93 | * @ticket 12480 |
| | 94 | */ |
| | 95 | public function test__fill_empty_links_returns_false_for_invalid_data() { |
| | 96 | $matches = array( |
| | 97 | '0' => 'This <a href="http://example.com"></a>is a link', |
| | 98 | ); |
| | 99 | |
| | 100 | $this->assertFalse( _fill_empty_links( $matches ) ); |
| | 101 | $this->assertFalse( _fill_empty_links( 'just a string' ) ); |
| | 102 | } |
| | 103 | } |