- Timestamp:
- 10/19/2020 11:37:53 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
r48937 r49215 9 9 public function test_add_to_links_with_target_blank() { 10 10 $content = '<p>Links: <a href="/" target="_blank">No rel</a></p>'; 11 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>';11 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener">No rel</a></p>'; 12 12 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 13 13 } … … 15 15 public function test_add_to_links_with_target_foo() { 16 16 $content = '<p>Links: <a href="/" target="foo">No rel</a></p>'; 17 $expected = '<p>Links: <a href="/" target="foo" rel="noopener noreferrer">No rel</a></p>';17 $expected = '<p>Links: <a href="/" target="foo" rel="noopener">No rel</a></p>'; 18 18 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 19 19 } … … 21 21 public function test_target_as_first_attribute() { 22 22 $content = '<p>Links: <a target="_blank" href="#">No rel</a></p>'; 23 $expected = '<p>Links: <a target="_blank" href="#" rel="noopener noreferrer">No rel</a></p>';23 $expected = '<p>Links: <a target="_blank" href="#" rel="noopener">No rel</a></p>'; 24 24 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 25 25 } … … 27 27 public function test_add_to_existing_rel() { 28 28 $content = '<p>Links: <a href="/" rel="existing values" target="_blank">Existing rel</a></p>'; 29 $expected = '<p>Links: <a href="/" rel="existing values noopener noreferrer" target="_blank">Existing rel</a></p>';29 $expected = '<p>Links: <a href="/" rel="existing values noopener" target="_blank">Existing rel</a></p>'; 30 30 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 31 31 } … … 33 33 public function test_no_duplicate_values_added() { 34 34 $content = '<p>Links: <a href="/" rel="existing noopener values" target="_blank">Existing rel</a></p>'; 35 $expected = '<p>Links: <a href="/" rel="existing noopener values noreferrer" target="_blank">Existing rel</a></p>';35 $expected = '<p>Links: <a href="/" rel="existing noopener values" target="_blank">Existing rel</a></p>'; 36 36 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 37 37 } … … 39 39 public function test_rel_with_single_quote_delimiter() { 40 40 $content = '<p>Links: <a href="/" rel=\'existing values\' target="_blank">Existing rel</a></p>'; 41 $expected = '<p>Links: <a href="/" rel="existing values noopener noreferrer" target="_blank">Existing rel</a></p>';41 $expected = '<p>Links: <a href="/" rel="existing values noopener" target="_blank">Existing rel</a></p>'; 42 42 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 43 43 } … … 45 45 public function test_rel_with_no_delimiter() { 46 46 $content = '<p>Links: <a href="/" rel=existing target="_blank">Existing rel</a></p>'; 47 $expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';47 $expected = '<p>Links: <a href="/" rel="existing noopener" target="_blank">Existing rel</a></p>'; 48 48 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 49 49 } … … 51 51 public function test_rel_value_spaced_and_no_delimiter() { 52 52 $content = '<p>Links: <a href="/" rel = existing target="_blank">Existing rel</a></p>'; 53 $expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';53 $expected = '<p>Links: <a href="/" rel="existing noopener" target="_blank">Existing rel</a></p>'; 54 54 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 55 55 } … … 57 57 public function test_escaped_quotes() { 58 58 $content = '<p>Links: <a href=\"/\" rel=\"existing values\" target=\"_blank\">Existing rel</a></p>'; 59 $expected = '<p>Links: <a href=\"/\" rel=\"existing values noopener noreferrer\" target=\"_blank\">Existing rel</a></p>';59 $expected = '<p>Links: <a href=\"/\" rel=\"existing values noopener\" target=\"_blank\">Existing rel</a></p>'; 60 60 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 61 61 } … … 63 63 public function test_ignore_links_with_no_target() { 64 64 $content = '<p>Links: <a href="/" target="_blank">Change me</a> <a href="/">Do not change me</a></p>'; 65 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>';65 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener">Change me</a> <a href="/">Do not change me</a></p>'; 66 66 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 67 67 } … … 86 86 public function test_wp_targeted_link_rel_filters_run() { 87 87 $content = '<p>Links: <a href="/" target="_blank">No rel</a></p>'; 88 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>';88 $expected = '<p>Links: <a href="/" target="_blank" rel="noopener">No rel</a></p>'; 89 89 90 90 $post = $this->factory()->post->create_and_get( … … 104 104 public function test_wp_targeted_link_rel_should_preserve_json() { 105 105 $content = '<p>Links: <a href=\"\/\" target=\"_blank\">No rel<\/a><\/p>'; 106 $expected = '<p>Links: <a href=\"\/\" target=\"_blank\" rel=\"noopener noreferrer\">No rel<\/a><\/p>';106 $expected = '<p>Links: <a href=\"\/\" target=\"_blank\" rel=\"noopener\">No rel<\/a><\/p>'; 107 107 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 108 108 } … … 115 115 public function test_wp_targeted_link_rel_skips_style_and_scripts() { 116 116 $content = '<style><a href="/" target=a></style><p>Links: <script>console.log("<a href=\'/\' target=a>hi</a>");</script><script>alert(1);</script>here <a href="/" target=_blank>aq</a></p><script>console.log("<a href=\'last\' target=\'_blank\'")</script>'; 117 $expected = '<style><a href="/" target=a></style><p>Links: <script>console.log("<a href=\'/\' target=a>hi</a>");</script><script>alert(1);</script>here <a href="/" target="_blank" rel="noopener noreferrer">aq</a></p><script>console.log("<a href=\'last\' target=\'_blank\'")</script>';117 $expected = '<style><a href="/" target=a></style><p>Links: <script>console.log("<a href=\'/\' target=a>hi</a>");</script><script>alert(1);</script>here <a href="/" target="_blank" rel="noopener">aq</a></p><script>console.log("<a href=\'last\' target=\'_blank\'")</script>'; 118 118 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 119 119 } … … 132 132 public function test_wp_targeted_link_rel_tab_separated_values_are_split() { 133 133 $content = "<p>Links: <a href=\"/\" target=\"_blank\" rel=\"ugc\t\tnoopener\t\">No rel</a></p>"; 134 $expected = '<p>Links: <a href="/" target="_blank" rel="ugc noopener noreferrer">No rel</a></p>';134 $expected = '<p>Links: <a href="/" target="_blank" rel="ugc noopener">No rel</a></p>'; 135 135 $this->assertSame( $expected, wp_targeted_link_rel( $content ) ); 136 136 }
Note: See TracChangeset
for help on using the changeset viewer.