PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / Integration / QuickEdit / Schemas / SocialLinkTest.php

SocialLinkTest.php in Extendify 3.1.0, at tests/Integration/QuickEdit/Schemas/SocialLinkTest.php

77 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Extendify\Tests\Integration\QuickEdit\Schemas;
4
5 use Extendify\QuickEdit\Schemas\SocialLink;
6 use WP_UnitTestCase;
7
8 class SocialLinkTest extends WP_UnitTestCase
9 {
10 public function test_fields_returns_single_url_field()
11 {
12 $fields = (new SocialLink())->fields();
13
14 $this->assertCount(1, $fields);
15 $this->assertSame('url', $fields[0]['key']);
16 $this->assertSame('link', $fields[0]['control']);
17 }
18
19 public function test_apply_url_sets_attrs_url()
20 {
21 $block = $this->socialLinkBlock(['service' => 'twitter']);
22
23 $result = (new SocialLink())->apply($block, 'url', 'https://example.test/profile');
24
25 $this->assertSame('https://example.test/profile', $result['attrs']['url']);
26 $this->assertSame('twitter', $result['attrs']['service']);
27 }
28
29 public function test_apply_url_strips_dangerous_schemes()
30 {
31 foreach (['javascript:alert(1)', 'data:text/html,<script>x</script>', 'vbscript:msgbox(1)'] as $url) {
32 $block = $this->socialLinkBlock(['service' => 'twitter']);
33 // esc_url_raw rejects the scheme → empty → attr left unset.
34 $result = (new SocialLink())->apply($block, 'url', $url);
35
36 $this->assertArrayNotHasKey('url', $result['attrs'], "url: {$url}");
37 }
38 }
39
40 public function test_apply_url_empty_string_unsets_attr()
41 {
42 $block = $this->socialLinkBlock(['service' => 'twitter', 'url' => 'https://example.test']);
43
44 $result = (new SocialLink())->apply($block, 'url', '');
45
46 $this->assertArrayNotHasKey('url', $result['attrs']);
47 $this->assertSame('twitter', $result['attrs']['service']);
48 }
49
50 public function test_apply_with_non_string_value_treats_as_empty()
51 {
52 $block = $this->socialLinkBlock(['url' => 'https://example.test']);
53
54 $result = (new SocialLink())->apply($block, 'url', null);
55
56 $this->assertArrayNotHasKey('url', $result['attrs']);
57 }
58
59 public function test_apply_with_unknown_field_returns_block_unchanged()
60 {
61 $block = $this->socialLinkBlock(['service' => 'twitter']);
62
63 $this->assertSame($block, (new SocialLink())->apply($block, 'service', 'github'));
64 }
65
66 private function socialLinkBlock(array $attrs): array
67 {
68 return [
69 'blockName' => 'core/social-link',
70 'attrs' => $attrs,
71 'innerBlocks' => [],
72 'innerHTML' => '',
73 'innerContent' => [],
74 ];
75 }
76 }
77