| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group oembed |
| | 5 | */ |
| | 6 | class Tests_Filter_oEmbed_Iframe_Title_Attribute extends WP_UnitTestCase { |
| | 7 | public function data_filter_oembed_iframe_title_attribute() { |
| | 8 | return array( |
| | 9 | array( |
| | 10 | '<p>Foo</p><iframe src=""></iframe><b>Bar</b>', |
| | 11 | array( |
| | 12 | 'type' => 'rich', |
| | 13 | ), |
| | 14 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 15 | '<p>Foo</p><iframe src=""></iframe><b>Bar</b>', |
| | 16 | ), |
| | 17 | array( |
| | 18 | '<p>Foo</p><iframe src="" title="Hello World"></iframe><b>Bar</b>', |
| | 19 | array( |
| | 20 | 'type' => 'rich', |
| | 21 | ), |
| | 22 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 23 | '<p>Foo</p><iframe title="Hello World" src=""></iframe><b>Bar</b>', |
| | 24 | ), |
| | 25 | array( |
| | 26 | '<p>Foo</p>', |
| | 27 | array( |
| | 28 | 'type' => 'rich', |
| | 29 | 'title' => 'Hello World', |
| | 30 | ), |
| | 31 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 32 | '<p>Foo</p>', |
| | 33 | ), |
| | 34 | array( |
| | 35 | '<p title="Foo">Bar</p>', |
| | 36 | array( |
| | 37 | 'type' => 'rich', |
| | 38 | 'title' => 'Hello World', |
| | 39 | ), |
| | 40 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 41 | '<p title="Foo">Bar</p>', |
| | 42 | ), |
| | 43 | array( |
| | 44 | '<p>Foo</p><iframe src=""></iframe><b>Bar</b>', |
| | 45 | array( |
| | 46 | 'type' => 'rich', |
| | 47 | 'title' => 'Hello World', |
| | 48 | ), |
| | 49 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 50 | '<p>Foo</p><iframe title="Hello World" src=""></iframe><b>Bar</b>', |
| | 51 | ), |
| | 52 | array( |
| | 53 | '<iframe src="" title="Foo"></iframe>', |
| | 54 | array( |
| | 55 | 'type' => 'rich', |
| | 56 | 'title' => 'Bar', |
| | 57 | ), |
| | 58 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| | 59 | '<iframe title="Foo" src=""></iframe>', |
| | 60 | ), |
| | 61 | ); |
| | 62 | } |
| | 63 | |
| | 64 | /** |
| | 65 | * @dataProvider data_filter_oembed_iframe_title_attribute |
| | 66 | */ |
| | 67 | public function test_oembed_iframe_title_attribute( $html, $oembed_data, $url, $expected ) { |
| | 68 | $actual = wp_filter_oembed_iframe_title_attribute( $html, (object) $oembed_data, $url ); |
| | 69 | |
| | 70 | $this->assertSame( $expected, $actual ); |
| | 71 | } |
| | 72 | |
| | 73 | public function test_filter_oembed_iframe_title_attribute() { |
| | 74 | add_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); |
| | 75 | |
| | 76 | $actual = wp_filter_oembed_iframe_title_attribute( |
| | 77 | '<iframe title="Foo" src=""></iframe>', |
| | 78 | (object) array( |
| | 79 | 'type' => 'rich', |
| | 80 | 'title' => 'Bar', |
| | 81 | ), |
| | 82 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' |
| | 83 | ); |
| | 84 | |
| | 85 | remove_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); |
| | 86 | |
| | 87 | $this->assertSame( '<iframe title="Baz" src=""></iframe>', $actual ); |
| | 88 | } |
| | 89 | |
| | 90 | public function test_filter_oembed_iframe_title_attribute_does_not_modify_other_tags() { |
| | 91 | add_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); |
| | 92 | |
| | 93 | $actual = wp_filter_oembed_iframe_title_attribute( |
| | 94 | '<p title="Bar">Baz</p><iframe title="Foo" src=""></iframe>', |
| | 95 | (object) array( |
| | 96 | 'type' => 'rich', |
| | 97 | 'title' => 'Bar', |
| | 98 | ), |
| | 99 | 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' |
| | 100 | ); |
| | 101 | |
| | 102 | remove_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); |
| | 103 | |
| | 104 | $this->assertSame( '<p title="Bar">Baz</p><iframe title="Baz" src=""></iframe>', $actual ); |
| | 105 | } |
| | 106 | |
| | 107 | public function _filter_oembed_iframe_title_attribute() { |
| | 108 | return 'Baz'; |
| | 109 | } |
| | 110 | } |