@@ -8,107 +8,107 @@ |
||
8 | 8 | */ |
9 | 9 | class SettingsTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - public function setUp() |
|
12 | - { |
|
13 | - parent::setUp(); |
|
14 | - require_once(VPMAUTIC_PLUGIN_DIR.'/options.php'); |
|
11 | + public function setUp() |
|
12 | + { |
|
13 | + parent::setUp(); |
|
14 | + require_once(VPMAUTIC_PLUGIN_DIR.'/options.php'); |
|
15 | 15 | |
16 | - $this->setOutputCallback(create_function('', '')); |
|
17 | - } |
|
16 | + $this->setOutputCallback(create_function('', '')); |
|
17 | + } |
|
18 | 18 | |
19 | - public function test_nonce_fields_are_present() |
|
20 | - { |
|
21 | - wpmautic_options_page(); |
|
22 | - $output = $this->getActualOutput(); |
|
23 | - $this->assertContains("name='option_page' value='wpmautic'", $output); |
|
24 | - } |
|
19 | + public function test_nonce_fields_are_present() |
|
20 | + { |
|
21 | + wpmautic_options_page(); |
|
22 | + $output = $this->getActualOutput(); |
|
23 | + $this->assertContains("name='option_page' value='wpmautic'", $output); |
|
24 | + } |
|
25 | 25 | |
26 | - public function test_with_admin_init() |
|
27 | - { |
|
28 | - wpmautic_admin_init(); |
|
29 | - wpmautic_options_page(); |
|
30 | - $output = $this->getActualOutput(); |
|
31 | - $this->assertContains("name='option_page' value='wpmautic'", $output); |
|
32 | - $this->test_base_url_setting(); |
|
33 | - $this->test_script_location_setting(); |
|
34 | - } |
|
26 | + public function test_with_admin_init() |
|
27 | + { |
|
28 | + wpmautic_admin_init(); |
|
29 | + wpmautic_options_page(); |
|
30 | + $output = $this->getActualOutput(); |
|
31 | + $this->assertContains("name='option_page' value='wpmautic'", $output); |
|
32 | + $this->test_base_url_setting(); |
|
33 | + $this->test_script_location_setting(); |
|
34 | + } |
|
35 | 35 | |
36 | - public function test_base_url_setting() |
|
37 | - { |
|
38 | - wpmautic_base_url(); |
|
39 | - $output = $this->getActualOutput(); |
|
40 | - $this->assertContains("wpmautic_base_url", $output); |
|
41 | - $this->assertContains("wpmautic_options[base_url]", $output); |
|
42 | - $this->assertContains("value=\"\"", $output); |
|
43 | - } |
|
36 | + public function test_base_url_setting() |
|
37 | + { |
|
38 | + wpmautic_base_url(); |
|
39 | + $output = $this->getActualOutput(); |
|
40 | + $this->assertContains("wpmautic_base_url", $output); |
|
41 | + $this->assertContains("wpmautic_options[base_url]", $output); |
|
42 | + $this->assertContains("value=\"\"", $output); |
|
43 | + } |
|
44 | 44 | |
45 | - public function test_base_url_setting_with_value() |
|
46 | - { |
|
47 | - update_option('wpmautic_options', array( |
|
48 | - 'base_url' => 'http://example.com' |
|
49 | - )); |
|
45 | + public function test_base_url_setting_with_value() |
|
46 | + { |
|
47 | + update_option('wpmautic_options', array( |
|
48 | + 'base_url' => 'http://example.com' |
|
49 | + )); |
|
50 | 50 | |
51 | - wpmautic_base_url(); |
|
52 | - $output = $this->getActualOutput(); |
|
53 | - $this->assertContains("wpmautic_base_url", $output); |
|
54 | - $this->assertContains("wpmautic_options[base_url]", $output); |
|
55 | - $this->assertContains("value=\"http://example.com\"", $output); |
|
56 | - } |
|
51 | + wpmautic_base_url(); |
|
52 | + $output = $this->getActualOutput(); |
|
53 | + $this->assertContains("wpmautic_base_url", $output); |
|
54 | + $this->assertContains("wpmautic_options[base_url]", $output); |
|
55 | + $this->assertContains("value=\"http://example.com\"", $output); |
|
56 | + } |
|
57 | 57 | |
58 | - public function test_script_location_setting() |
|
59 | - { |
|
60 | - wpmautic_script_location(); |
|
61 | - $output = $this->getActualOutput(); |
|
62 | - $this->assertContains("wpmautic_script_location", $output); |
|
63 | - $this->assertContains("wpmautic_options[script_location]", $output); |
|
64 | - $this->assertRegExp('/value="header"\s+checked/', $output); |
|
65 | - } |
|
58 | + public function test_script_location_setting() |
|
59 | + { |
|
60 | + wpmautic_script_location(); |
|
61 | + $output = $this->getActualOutput(); |
|
62 | + $this->assertContains("wpmautic_script_location", $output); |
|
63 | + $this->assertContains("wpmautic_options[script_location]", $output); |
|
64 | + $this->assertRegExp('/value="header"\s+checked/', $output); |
|
65 | + } |
|
66 | 66 | |
67 | - public function test_script_location_setting_with_footer_checked() |
|
68 | - { |
|
69 | - update_option('wpmautic_options', array( |
|
70 | - 'script_location' => 'footer' |
|
71 | - )); |
|
67 | + public function test_script_location_setting_with_footer_checked() |
|
68 | + { |
|
69 | + update_option('wpmautic_options', array( |
|
70 | + 'script_location' => 'footer' |
|
71 | + )); |
|
72 | 72 | |
73 | - wpmautic_script_location(); |
|
74 | - $output = $this->getActualOutput(); |
|
75 | - $this->assertContains("wpmautic_script_location", $output); |
|
76 | - $this->assertContains("wpmautic_options[script_location]", $output); |
|
77 | - $this->assertRegExp('/value="footer"\s+checked/', $output); |
|
78 | - } |
|
73 | + wpmautic_script_location(); |
|
74 | + $output = $this->getActualOutput(); |
|
75 | + $this->assertContains("wpmautic_script_location", $output); |
|
76 | + $this->assertContains("wpmautic_options[script_location]", $output); |
|
77 | + $this->assertRegExp('/value="footer"\s+checked/', $output); |
|
78 | + } |
|
79 | 79 | |
80 | - public function test_fallback_activated_setting_with_default() |
|
81 | - { |
|
82 | - wpmautic_fallback_activated(); |
|
83 | - $output = $this->getActualOutput(); |
|
84 | - $this->assertContains("wpmautic_fallback_activated", $output); |
|
85 | - $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
86 | - $this->assertContains("checked", $output); |
|
87 | - } |
|
80 | + public function test_fallback_activated_setting_with_default() |
|
81 | + { |
|
82 | + wpmautic_fallback_activated(); |
|
83 | + $output = $this->getActualOutput(); |
|
84 | + $this->assertContains("wpmautic_fallback_activated", $output); |
|
85 | + $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
86 | + $this->assertContains("checked", $output); |
|
87 | + } |
|
88 | 88 | |
89 | - public function test_fallback_activated_setting_with_unchecked() |
|
90 | - { |
|
91 | - update_option('wpmautic_options', array( |
|
92 | - 'fallback_activated' => false |
|
93 | - )); |
|
89 | + public function test_fallback_activated_setting_with_unchecked() |
|
90 | + { |
|
91 | + update_option('wpmautic_options', array( |
|
92 | + 'fallback_activated' => false |
|
93 | + )); |
|
94 | 94 | |
95 | - wpmautic_fallback_activated(); |
|
96 | - $output = $this->getActualOutput(); |
|
97 | - $this->assertContains("wpmautic_fallback_activated", $output); |
|
98 | - $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
99 | - $this->assertNotContains("checked", $output); |
|
100 | - } |
|
95 | + wpmautic_fallback_activated(); |
|
96 | + $output = $this->getActualOutput(); |
|
97 | + $this->assertContains("wpmautic_fallback_activated", $output); |
|
98 | + $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
99 | + $this->assertNotContains("checked", $output); |
|
100 | + } |
|
101 | 101 | |
102 | - public function test_fallback_activated_setting_with_checked() |
|
103 | - { |
|
104 | - update_option('wpmautic_options', array( |
|
105 | - 'fallback_activated' => true |
|
106 | - )); |
|
102 | + public function test_fallback_activated_setting_with_checked() |
|
103 | + { |
|
104 | + update_option('wpmautic_options', array( |
|
105 | + 'fallback_activated' => true |
|
106 | + )); |
|
107 | 107 | |
108 | - wpmautic_fallback_activated(); |
|
109 | - $output = $this->getActualOutput(); |
|
110 | - $this->assertContains("wpmautic_fallback_activated", $output); |
|
111 | - $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
112 | - $this->assertContains("checked", $output); |
|
113 | - } |
|
108 | + wpmautic_fallback_activated(); |
|
109 | + $output = $this->getActualOutput(); |
|
110 | + $this->assertContains("wpmautic_fallback_activated", $output); |
|
111 | + $this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
112 | + $this->assertContains("checked", $output); |
|
113 | + } |
|
114 | 114 | } |
@@ -8,55 +8,55 @@ |
||
8 | 8 | */ |
9 | 9 | class OptionsTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - /** |
|
12 | - * @expectedException InvalidArgumentException |
|
13 | - */ |
|
14 | - public function test_invalid_option_name() |
|
15 | - { |
|
16 | - wpmautic_option('azerty123456'); |
|
17 | - } |
|
11 | + /** |
|
12 | + * @expectedException InvalidArgumentException |
|
13 | + */ |
|
14 | + public function test_invalid_option_name() |
|
15 | + { |
|
16 | + wpmautic_option('azerty123456'); |
|
17 | + } |
|
18 | 18 | |
19 | - public function test_base_url_when_empty() |
|
20 | - { |
|
21 | - update_option('wpmautic_options', array( |
|
22 | - 'base_url' => '' |
|
23 | - )); |
|
24 | - $this->assertEmpty(wpmautic_option('base_url')); |
|
25 | - } |
|
19 | + public function test_base_url_when_empty() |
|
20 | + { |
|
21 | + update_option('wpmautic_options', array( |
|
22 | + 'base_url' => '' |
|
23 | + )); |
|
24 | + $this->assertEmpty(wpmautic_option('base_url')); |
|
25 | + } |
|
26 | 26 | |
27 | - public function test_base_url_with_value() |
|
28 | - { |
|
29 | - update_option('wpmautic_options', array( |
|
30 | - 'base_url' => 'http://example.com' |
|
31 | - )); |
|
32 | - $this->assertEquals('http://example.com', wpmautic_option('base_url')); |
|
33 | - } |
|
27 | + public function test_base_url_with_value() |
|
28 | + { |
|
29 | + update_option('wpmautic_options', array( |
|
30 | + 'base_url' => 'http://example.com' |
|
31 | + )); |
|
32 | + $this->assertEquals('http://example.com', wpmautic_option('base_url')); |
|
33 | + } |
|
34 | 34 | |
35 | - public function test_script_location_when_empty() |
|
36 | - { |
|
37 | - update_option('wpmautic_options', array()); |
|
38 | - $this->assertEquals('header', wpmautic_option('script_location')); |
|
39 | - } |
|
35 | + public function test_script_location_when_empty() |
|
36 | + { |
|
37 | + update_option('wpmautic_options', array()); |
|
38 | + $this->assertEquals('header', wpmautic_option('script_location')); |
|
39 | + } |
|
40 | 40 | |
41 | - public function test_script_location_with_value() |
|
42 | - { |
|
43 | - update_option('wpmautic_options', array( |
|
44 | - 'script_location' => 'footer' |
|
45 | - )); |
|
46 | - $this->assertEquals('footer', wpmautic_option('script_location')); |
|
47 | - } |
|
41 | + public function test_script_location_with_value() |
|
42 | + { |
|
43 | + update_option('wpmautic_options', array( |
|
44 | + 'script_location' => 'footer' |
|
45 | + )); |
|
46 | + $this->assertEquals('footer', wpmautic_option('script_location')); |
|
47 | + } |
|
48 | 48 | |
49 | - public function test_fallback_activated_when_empty() |
|
50 | - { |
|
51 | - update_option('wpmautic_options', array()); |
|
52 | - $this->assertTrue(wpmautic_option('fallback_activated')); |
|
53 | - } |
|
49 | + public function test_fallback_activated_when_empty() |
|
50 | + { |
|
51 | + update_option('wpmautic_options', array()); |
|
52 | + $this->assertTrue(wpmautic_option('fallback_activated')); |
|
53 | + } |
|
54 | 54 | |
55 | - public function test_fallback_activated_with_value() |
|
56 | - { |
|
57 | - update_option('wpmautic_options', array( |
|
58 | - 'fallback_activated' => false |
|
59 | - )); |
|
60 | - $this->assertFalse(wpmautic_option('fallback_activated')); |
|
61 | - } |
|
55 | + public function test_fallback_activated_with_value() |
|
56 | + { |
|
57 | + update_option('wpmautic_options', array( |
|
58 | + 'fallback_activated' => false |
|
59 | + )); |
|
60 | + $this->assertFalse(wpmautic_option('fallback_activated')); |
|
61 | + } |
|
62 | 62 | } |
@@ -8,238 +8,238 @@ |
||
8 | 8 | */ |
9 | 9 | class ShortCodeTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - public function setUp() |
|
12 | - { |
|
13 | - parent::setUp(); |
|
11 | + public function setUp() |
|
12 | + { |
|
13 | + parent::setUp(); |
|
14 | 14 | |
15 | - update_option('wpmautic_options', array( |
|
16 | - 'base_url' => 'http://example.com' |
|
17 | - )); |
|
18 | - } |
|
15 | + update_option('wpmautic_options', array( |
|
16 | + 'base_url' => 'http://example.com' |
|
17 | + )); |
|
18 | + } |
|
19 | 19 | |
20 | - public function test_shortcode_exists() |
|
21 | - { |
|
22 | - $this->assertTrue(shortcode_exists('mautic')); |
|
23 | - $this->assertTrue(shortcode_exists('mauticcontent')); |
|
24 | - $this->assertTrue(shortcode_exists('mauticvideo')); |
|
25 | - $this->assertTrue(shortcode_exists('mauticform')); |
|
26 | - $this->assertTrue(shortcode_exists('mautictags')); |
|
27 | - $this->assertTrue(shortcode_exists('mauticfocus')); |
|
28 | - } |
|
20 | + public function test_shortcode_exists() |
|
21 | + { |
|
22 | + $this->assertTrue(shortcode_exists('mautic')); |
|
23 | + $this->assertTrue(shortcode_exists('mauticcontent')); |
|
24 | + $this->assertTrue(shortcode_exists('mauticvideo')); |
|
25 | + $this->assertTrue(shortcode_exists('mauticform')); |
|
26 | + $this->assertTrue(shortcode_exists('mautictags')); |
|
27 | + $this->assertTrue(shortcode_exists('mauticfocus')); |
|
28 | + } |
|
29 | 29 | |
30 | - public function test_form_shortcode_from_empty_atts() |
|
31 | - { |
|
32 | - $result = wpmautic_form_shortcode(array()); |
|
33 | - $this->assertFalse($result); |
|
34 | - } |
|
30 | + public function test_form_shortcode_from_empty_atts() |
|
31 | + { |
|
32 | + $result = wpmautic_form_shortcode(array()); |
|
33 | + $this->assertFalse($result); |
|
34 | + } |
|
35 | 35 | |
36 | - public function provideShortCode() |
|
37 | - { |
|
38 | - return array( |
|
39 | - array( |
|
40 | - '[mauticform id="1"]', |
|
41 | - '<script type="text/javascript" src="http://example.com/form/generate.js?id=1"></script>' |
|
42 | - ), |
|
43 | - array( |
|
44 | - '[mautic type="form" id="1"]', |
|
45 | - '<script type="text/javascript" src="http://example.com/form/generate.js?id=1"></script>' |
|
46 | - ), |
|
47 | - array( |
|
48 | - '[mautictags values="tag,-tag2,tag3"]', |
|
49 | - '<img src="http://example.com/mtracking.gif?tags=tag,-tag2,tag3" alt="Mautic Tags" />' |
|
50 | - ), |
|
51 | - array( |
|
52 | - '[mautic type="tags" values="tag,tag2,-tag3"]', |
|
53 | - '<img src="http://example.com/mtracking.gif?tags=tag,tag2,-tag3" alt="Mautic Tags" />' |
|
54 | - ), |
|
55 | - array( |
|
56 | - '[mautictags values="tag,-tag2,tag3"]', |
|
57 | - '<img src="http://example.com/mtracking.gif?tags=tag,-tag2,tag3" alt="Mautic Tags" />' |
|
58 | - ), |
|
59 | - array( |
|
60 | - '[mautic type="tags" values="tag,tag2,-tag3"]', |
|
61 | - '<img src="http://example.com/mtracking.gif?tags=tag,tag2,-tag3" alt="Mautic Tags" />' |
|
62 | - ), |
|
63 | - array( |
|
64 | - '[mauticfocus id="1"]', |
|
65 | - '<script type="text/javascript" src="http://example.com/focus/1.js" async="async"></script>' |
|
66 | - ), |
|
67 | - array( |
|
68 | - '[mautic type="focus" id="1"]', |
|
69 | - '<script type="text/javascript" src="http://example.com/focus/1.js" async="async"></script>' |
|
70 | - ), |
|
71 | - array( |
|
72 | - '[mauticcontent slot="name"]content[/mauticcontent]', |
|
73 | - '<div class="mautic-slot" data-slot-name="name">content</div>' |
|
74 | - ), |
|
75 | - array( |
|
76 | - '[mautic type="content" slot="name"]content[/mautic]', |
|
77 | - '<div class="mautic-slot" data-slot-name="name">content</div>' |
|
78 | - ), |
|
79 | - array( |
|
80 | - '[mautic type="video" src="https://www.youtube.com/watch?v=1234" form-id="1" width="148"]', |
|
81 | - '<video height="360" width="148" data-form-id="1" data-gate-time="15">' . |
|
82 | - '<source type="video/youtube" src="https://www.youtube.com/watch?v=1234" />' . |
|
83 | - '</video>' |
|
84 | - ), |
|
85 | - array( |
|
86 | - '[mauticvideo src="https://www.youtube.com/watch?v=1234" form-id="1" width="148"]', |
|
87 | - '<video height="360" width="148" data-form-id="1" data-gate-time="15">' . |
|
88 | - '<source type="video/youtube" src="https://www.youtube.com/watch?v=1234" />' . |
|
89 | - '</video>' |
|
90 | - ), |
|
91 | - array( |
|
92 | - '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" height="272"]', |
|
93 | - '<video height="272" width="640" data-form-id="1" data-gate-time="15">' . |
|
94 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
95 | - '</video>' |
|
96 | - ), |
|
97 | - array( |
|
98 | - '[mauticvideo src="https://vimeo.com/218680983" form-id="1" height="272"]', |
|
99 | - '<video height="272" width="640" data-form-id="1" data-gate-time="15">' . |
|
100 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
101 | - '</video>' |
|
102 | - ), |
|
103 | - array( |
|
104 | - '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" gate-time="25"]', |
|
105 | - '<video height="360" width="640" data-form-id="1" data-gate-time="25">' . |
|
106 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
107 | - '</video>' |
|
108 | - ), |
|
109 | - array( |
|
110 | - '[mauticvideo src="https://vimeo.com/218680983" form-id="1" gate-time="25"]', |
|
111 | - '<video height="360" width="640" data-form-id="1" data-gate-time="25">' . |
|
112 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
113 | - '</video>' |
|
114 | - ), |
|
115 | - array( |
|
116 | - '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" video-type="mp4"]', |
|
117 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
118 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
119 | - '</video>' |
|
120 | - ), |
|
121 | - array( |
|
122 | - '[mauticvideo src="https://vimeo.com/218680983" form-id="1" video-type="mp4"]', |
|
123 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
124 | - '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
125 | - '</video>' |
|
126 | - ), |
|
127 | - array( |
|
128 | - '[mautic type="video" src="https://example.com/mavideo.mov" form-id="1" video-type="mov"]', |
|
129 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
130 | - '<source type="video/mov" src="https://example.com/mavideo.mov" />' . |
|
131 | - '</video>' |
|
132 | - ), |
|
133 | - array( |
|
134 | - '[mauticvideo src="https://example.com/mavideo.mov" form-id="1" video-type="mov"]', |
|
135 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
136 | - '<source type="video/mov" src="https://example.com/mavideo.mov" />' . |
|
137 | - '</video>' |
|
138 | - ), |
|
139 | - array( |
|
140 | - '[mautic type="video" src="https://example.com/mavideo.mp4" form-id="1"]', |
|
141 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
142 | - '<source type="video/mp4" src="https://example.com/mavideo.mp4" />' . |
|
143 | - '</video>' |
|
144 | - ), |
|
145 | - array( |
|
146 | - '[mauticvideo src="https://example.com/mavideo.mp4" form-id="1"]', |
|
147 | - '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
148 | - '<source type="video/mp4" src="https://example.com/mavideo.mp4" />' . |
|
149 | - '</video>' |
|
150 | - ), |
|
151 | - ); |
|
152 | - } |
|
36 | + public function provideShortCode() |
|
37 | + { |
|
38 | + return array( |
|
39 | + array( |
|
40 | + '[mauticform id="1"]', |
|
41 | + '<script type="text/javascript" src="http://example.com/form/generate.js?id=1"></script>' |
|
42 | + ), |
|
43 | + array( |
|
44 | + '[mautic type="form" id="1"]', |
|
45 | + '<script type="text/javascript" src="http://example.com/form/generate.js?id=1"></script>' |
|
46 | + ), |
|
47 | + array( |
|
48 | + '[mautictags values="tag,-tag2,tag3"]', |
|
49 | + '<img src="http://example.com/mtracking.gif?tags=tag,-tag2,tag3" alt="Mautic Tags" />' |
|
50 | + ), |
|
51 | + array( |
|
52 | + '[mautic type="tags" values="tag,tag2,-tag3"]', |
|
53 | + '<img src="http://example.com/mtracking.gif?tags=tag,tag2,-tag3" alt="Mautic Tags" />' |
|
54 | + ), |
|
55 | + array( |
|
56 | + '[mautictags values="tag,-tag2,tag3"]', |
|
57 | + '<img src="http://example.com/mtracking.gif?tags=tag,-tag2,tag3" alt="Mautic Tags" />' |
|
58 | + ), |
|
59 | + array( |
|
60 | + '[mautic type="tags" values="tag,tag2,-tag3"]', |
|
61 | + '<img src="http://example.com/mtracking.gif?tags=tag,tag2,-tag3" alt="Mautic Tags" />' |
|
62 | + ), |
|
63 | + array( |
|
64 | + '[mauticfocus id="1"]', |
|
65 | + '<script type="text/javascript" src="http://example.com/focus/1.js" async="async"></script>' |
|
66 | + ), |
|
67 | + array( |
|
68 | + '[mautic type="focus" id="1"]', |
|
69 | + '<script type="text/javascript" src="http://example.com/focus/1.js" async="async"></script>' |
|
70 | + ), |
|
71 | + array( |
|
72 | + '[mauticcontent slot="name"]content[/mauticcontent]', |
|
73 | + '<div class="mautic-slot" data-slot-name="name">content</div>' |
|
74 | + ), |
|
75 | + array( |
|
76 | + '[mautic type="content" slot="name"]content[/mautic]', |
|
77 | + '<div class="mautic-slot" data-slot-name="name">content</div>' |
|
78 | + ), |
|
79 | + array( |
|
80 | + '[mautic type="video" src="https://www.youtube.com/watch?v=1234" form-id="1" width="148"]', |
|
81 | + '<video height="360" width="148" data-form-id="1" data-gate-time="15">' . |
|
82 | + '<source type="video/youtube" src="https://www.youtube.com/watch?v=1234" />' . |
|
83 | + '</video>' |
|
84 | + ), |
|
85 | + array( |
|
86 | + '[mauticvideo src="https://www.youtube.com/watch?v=1234" form-id="1" width="148"]', |
|
87 | + '<video height="360" width="148" data-form-id="1" data-gate-time="15">' . |
|
88 | + '<source type="video/youtube" src="https://www.youtube.com/watch?v=1234" />' . |
|
89 | + '</video>' |
|
90 | + ), |
|
91 | + array( |
|
92 | + '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" height="272"]', |
|
93 | + '<video height="272" width="640" data-form-id="1" data-gate-time="15">' . |
|
94 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
95 | + '</video>' |
|
96 | + ), |
|
97 | + array( |
|
98 | + '[mauticvideo src="https://vimeo.com/218680983" form-id="1" height="272"]', |
|
99 | + '<video height="272" width="640" data-form-id="1" data-gate-time="15">' . |
|
100 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
101 | + '</video>' |
|
102 | + ), |
|
103 | + array( |
|
104 | + '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" gate-time="25"]', |
|
105 | + '<video height="360" width="640" data-form-id="1" data-gate-time="25">' . |
|
106 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
107 | + '</video>' |
|
108 | + ), |
|
109 | + array( |
|
110 | + '[mauticvideo src="https://vimeo.com/218680983" form-id="1" gate-time="25"]', |
|
111 | + '<video height="360" width="640" data-form-id="1" data-gate-time="25">' . |
|
112 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
113 | + '</video>' |
|
114 | + ), |
|
115 | + array( |
|
116 | + '[mautic type="video" src="https://vimeo.com/218680983" form-id="1" video-type="mp4"]', |
|
117 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
118 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
119 | + '</video>' |
|
120 | + ), |
|
121 | + array( |
|
122 | + '[mauticvideo src="https://vimeo.com/218680983" form-id="1" video-type="mp4"]', |
|
123 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
124 | + '<source type="video/vimeo" src="https://vimeo.com/218680983" />' . |
|
125 | + '</video>' |
|
126 | + ), |
|
127 | + array( |
|
128 | + '[mautic type="video" src="https://example.com/mavideo.mov" form-id="1" video-type="mov"]', |
|
129 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
130 | + '<source type="video/mov" src="https://example.com/mavideo.mov" />' . |
|
131 | + '</video>' |
|
132 | + ), |
|
133 | + array( |
|
134 | + '[mauticvideo src="https://example.com/mavideo.mov" form-id="1" video-type="mov"]', |
|
135 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
136 | + '<source type="video/mov" src="https://example.com/mavideo.mov" />' . |
|
137 | + '</video>' |
|
138 | + ), |
|
139 | + array( |
|
140 | + '[mautic type="video" src="https://example.com/mavideo.mp4" form-id="1"]', |
|
141 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
142 | + '<source type="video/mp4" src="https://example.com/mavideo.mp4" />' . |
|
143 | + '</video>' |
|
144 | + ), |
|
145 | + array( |
|
146 | + '[mauticvideo src="https://example.com/mavideo.mp4" form-id="1"]', |
|
147 | + '<video height="360" width="640" data-form-id="1" data-gate-time="15">' . |
|
148 | + '<source type="video/mp4" src="https://example.com/mavideo.mp4" />' . |
|
149 | + '</video>' |
|
150 | + ), |
|
151 | + ); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @dataProvider provideShortCode |
|
156 | - * @param string $content |
|
157 | - * @param string $expected |
|
158 | - */ |
|
159 | - public function test_shortcode($content, $expected) |
|
160 | - { |
|
161 | - $result = do_shortcode($content); |
|
162 | - $this->assertEquals($expected, $result); |
|
163 | - } |
|
154 | + /** |
|
155 | + * @dataProvider provideShortCode |
|
156 | + * @param string $content |
|
157 | + * @param string $expected |
|
158 | + */ |
|
159 | + public function test_shortcode($content, $expected) |
|
160 | + { |
|
161 | + $result = do_shortcode($content); |
|
162 | + $this->assertEquals($expected, $result); |
|
163 | + } |
|
164 | 164 | |
165 | - public function provideShortCodeToBeEmptyWithoutUrl() |
|
166 | - { |
|
167 | - return array( |
|
168 | - array('[mauticform id="1"]'), |
|
169 | - array('[mautic type="form" id="1"]'), |
|
170 | - array('[mautictags values="tag,-tag2,tag3"]'), |
|
171 | - array('[mautic type="tags" values="tag,tag2,-tag3"]'), |
|
172 | - array('[mauticfocus id="1"]'), |
|
173 | - array('[mautic type="focus" id="1"]'), |
|
174 | - ); |
|
175 | - } |
|
165 | + public function provideShortCodeToBeEmptyWithoutUrl() |
|
166 | + { |
|
167 | + return array( |
|
168 | + array('[mauticform id="1"]'), |
|
169 | + array('[mautic type="form" id="1"]'), |
|
170 | + array('[mautictags values="tag,-tag2,tag3"]'), |
|
171 | + array('[mautic type="tags" values="tag,tag2,-tag3"]'), |
|
172 | + array('[mauticfocus id="1"]'), |
|
173 | + array('[mautic type="focus" id="1"]'), |
|
174 | + ); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @dataProvider provideShortCodeToBeEmpty |
|
179 | - * @param string $content |
|
180 | - */ |
|
181 | - public function test_shortcode_with_empty_url($content) |
|
182 | - { |
|
183 | - update_option('wpmautic_options', array()); |
|
177 | + /** |
|
178 | + * @dataProvider provideShortCodeToBeEmpty |
|
179 | + * @param string $content |
|
180 | + */ |
|
181 | + public function test_shortcode_with_empty_url($content) |
|
182 | + { |
|
183 | + update_option('wpmautic_options', array()); |
|
184 | 184 | |
185 | - $result = do_shortcode($content); |
|
186 | - $this->assertEmpty($result); |
|
187 | - } |
|
185 | + $result = do_shortcode($content); |
|
186 | + $this->assertEmpty($result); |
|
187 | + } |
|
188 | 188 | |
189 | - public function provideShortCodeToBeEmpty() |
|
190 | - { |
|
191 | - return array( |
|
192 | - array('[mauticform]'), |
|
193 | - array('[mautic type="form"]'), |
|
194 | - array('[mautictags]'), |
|
195 | - array('[mautic type="tags"]'), |
|
196 | - array('[mauticfocus]'), |
|
197 | - array('[mautic type="focus"]'), |
|
198 | - ); |
|
199 | - } |
|
189 | + public function provideShortCodeToBeEmpty() |
|
190 | + { |
|
191 | + return array( |
|
192 | + array('[mauticform]'), |
|
193 | + array('[mautic type="form"]'), |
|
194 | + array('[mautictags]'), |
|
195 | + array('[mautic type="tags"]'), |
|
196 | + array('[mauticfocus]'), |
|
197 | + array('[mautic type="focus"]'), |
|
198 | + ); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @dataProvider provideShortCodeToBeEmpty |
|
203 | - * @param string $content |
|
204 | - */ |
|
205 | - public function test_shortcode_to_be_empty($content) |
|
206 | - { |
|
207 | - $result = do_shortcode($content); |
|
208 | - $this->assertEmpty($result); |
|
209 | - } |
|
201 | + /** |
|
202 | + * @dataProvider provideShortCodeToBeEmpty |
|
203 | + * @param string $content |
|
204 | + */ |
|
205 | + public function test_shortcode_to_be_empty($content) |
|
206 | + { |
|
207 | + $result = do_shortcode($content); |
|
208 | + $this->assertEmpty($result); |
|
209 | + } |
|
210 | 210 | |
211 | - public function test_invalid_shortcode_type() |
|
212 | - { |
|
213 | - $result = do_shortcode("[mautic type='azerty']"); |
|
214 | - $this->assertEmpty($result); |
|
215 | - } |
|
211 | + public function test_invalid_shortcode_type() |
|
212 | + { |
|
213 | + $result = do_shortcode("[mautic type='azerty']"); |
|
214 | + $this->assertEmpty($result); |
|
215 | + } |
|
216 | 216 | |
217 | - public function test_no_src_on_video_shortcode() |
|
218 | - { |
|
219 | - $result = do_shortcode("[mautic type='video']"); |
|
220 | - $this->assertEquals( |
|
221 | - 'You must provide a video source. Add a src="URL" attribute to your shortcode. '. |
|
222 | - 'Replace URL with the source url for your video.', |
|
223 | - $result |
|
224 | - ); |
|
225 | - } |
|
217 | + public function test_no_src_on_video_shortcode() |
|
218 | + { |
|
219 | + $result = do_shortcode("[mautic type='video']"); |
|
220 | + $this->assertEquals( |
|
221 | + 'You must provide a video source. Add a src="URL" attribute to your shortcode. '. |
|
222 | + 'Replace URL with the source url for your video.', |
|
223 | + $result |
|
224 | + ); |
|
225 | + } |
|
226 | 226 | |
227 | - public function test_no_form_id_on_video_shortcode() |
|
228 | - { |
|
229 | - $result = do_shortcode("[mautic type='video' src='mavideo.mov']"); |
|
230 | - $this->assertEquals( |
|
231 | - 'You must provide a mautic form id. Add a form-id="#" attribute to your shortcode. '. |
|
232 | - 'Replace # with the id of the form you want to use.', |
|
233 | - $result |
|
234 | - ); |
|
235 | - } |
|
227 | + public function test_no_form_id_on_video_shortcode() |
|
228 | + { |
|
229 | + $result = do_shortcode("[mautic type='video' src='mavideo.mov']"); |
|
230 | + $this->assertEquals( |
|
231 | + 'You must provide a mautic form id. Add a form-id="#" attribute to your shortcode. '. |
|
232 | + 'Replace # with the id of the form you want to use.', |
|
233 | + $result |
|
234 | + ); |
|
235 | + } |
|
236 | 236 | |
237 | - public function test_no_video_type_on_video_shortcode() |
|
238 | - { |
|
239 | - $result = do_shortcode("[mautic type='video' src='mavideo.mov' form-id='1']"); |
|
240 | - $this->assertEquals( |
|
241 | - 'Please define a valid video type with video-type="#".', |
|
242 | - $result |
|
243 | - ); |
|
244 | - } |
|
237 | + public function test_no_video_type_on_video_shortcode() |
|
238 | + { |
|
239 | + $result = do_shortcode("[mautic type='video' src='mavideo.mov' form-id='1']"); |
|
240 | + $this->assertEquals( |
|
241 | + 'Please define a valid video type with video-type="#".', |
|
242 | + $result |
|
243 | + ); |
|
244 | + } |
|
245 | 245 | } |
@@ -8,62 +8,62 @@ |
||
8 | 8 | */ |
9 | 9 | class OptionsValidationTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - public function setUp() |
|
12 | - { |
|
13 | - parent::setUp(); |
|
14 | - require_once(VPMAUTIC_PLUGIN_DIR.'/options.php'); |
|
15 | - } |
|
11 | + public function setUp() |
|
12 | + { |
|
13 | + parent::setUp(); |
|
14 | + require_once(VPMAUTIC_PLUGIN_DIR.'/options.php'); |
|
15 | + } |
|
16 | 16 | |
17 | - public function test_validation_when_empty() |
|
18 | - { |
|
19 | - $options = wpmautic_options_validate(array()); |
|
20 | - $this->assertArrayHasKey('base_url', $options); |
|
21 | - $this->assertArrayHasKey('script_location', $options); |
|
22 | - $this->assertArrayHasKey('fallback_activated', $options); |
|
23 | - $this->assertEmpty($options['base_url']); |
|
24 | - $this->assertEquals('header', $options['script_location']); |
|
25 | - $this->assertFalse($options['fallback_activated']); |
|
26 | - } |
|
17 | + public function test_validation_when_empty() |
|
18 | + { |
|
19 | + $options = wpmautic_options_validate(array()); |
|
20 | + $this->assertArrayHasKey('base_url', $options); |
|
21 | + $this->assertArrayHasKey('script_location', $options); |
|
22 | + $this->assertArrayHasKey('fallback_activated', $options); |
|
23 | + $this->assertEmpty($options['base_url']); |
|
24 | + $this->assertEquals('header', $options['script_location']); |
|
25 | + $this->assertFalse($options['fallback_activated']); |
|
26 | + } |
|
27 | 27 | |
28 | - public function test_validation_with_invalid_script_location() |
|
29 | - { |
|
30 | - $options = wpmautic_options_validate(array( |
|
31 | - 'script_location' => 'toto' |
|
32 | - )); |
|
33 | - $this->assertEquals('header', $options['script_location']); |
|
34 | - } |
|
28 | + public function test_validation_with_invalid_script_location() |
|
29 | + { |
|
30 | + $options = wpmautic_options_validate(array( |
|
31 | + 'script_location' => 'toto' |
|
32 | + )); |
|
33 | + $this->assertEquals('header', $options['script_location']); |
|
34 | + } |
|
35 | 35 | |
36 | - public function test_validation_with_whitespaces_in_values() |
|
37 | - { |
|
38 | - $options = wpmautic_options_validate(array( |
|
39 | - 'base_url' => ' http://example.com ', |
|
40 | - 'script_location' => ' footer ' |
|
41 | - )); |
|
42 | - $this->assertEquals('http://example.com', $options['base_url']); |
|
43 | - $this->assertEquals('footer', $options['script_location']); |
|
44 | - } |
|
36 | + public function test_validation_with_whitespaces_in_values() |
|
37 | + { |
|
38 | + $options = wpmautic_options_validate(array( |
|
39 | + 'base_url' => ' http://example.com ', |
|
40 | + 'script_location' => ' footer ' |
|
41 | + )); |
|
42 | + $this->assertEquals('http://example.com', $options['base_url']); |
|
43 | + $this->assertEquals('footer', $options['script_location']); |
|
44 | + } |
|
45 | 45 | |
46 | - public function test_validation_with_invalid_url() |
|
47 | - { |
|
48 | - $options = wpmautic_options_validate(array( |
|
49 | - 'base_url' => 'url' |
|
50 | - )); |
|
51 | - $this->assertEquals('http://url', $options['base_url']); |
|
52 | - } |
|
46 | + public function test_validation_with_invalid_url() |
|
47 | + { |
|
48 | + $options = wpmautic_options_validate(array( |
|
49 | + 'base_url' => 'url' |
|
50 | + )); |
|
51 | + $this->assertEquals('http://url', $options['base_url']); |
|
52 | + } |
|
53 | 53 | |
54 | - public function test_validation_with_invalid_fallback_activated() |
|
55 | - { |
|
56 | - $options = wpmautic_options_validate(array( |
|
57 | - 'fallback_activated' => 'toto' |
|
58 | - )); |
|
59 | - $this->assertFalse($options['fallback_activated']); |
|
60 | - } |
|
54 | + public function test_validation_with_invalid_fallback_activated() |
|
55 | + { |
|
56 | + $options = wpmautic_options_validate(array( |
|
57 | + 'fallback_activated' => 'toto' |
|
58 | + )); |
|
59 | + $this->assertFalse($options['fallback_activated']); |
|
60 | + } |
|
61 | 61 | |
62 | - public function test_validation_with_valid_fallback_activated() |
|
63 | - { |
|
64 | - $options = wpmautic_options_validate(array( |
|
65 | - 'fallback_activated' => '1' |
|
66 | - )); |
|
67 | - $this->assertTrue($options['fallback_activated']); |
|
68 | - } |
|
62 | + public function test_validation_with_valid_fallback_activated() |
|
63 | + { |
|
64 | + $options = wpmautic_options_validate(array( |
|
65 | + 'fallback_activated' => '1' |
|
66 | + )); |
|
67 | + $this->assertTrue($options['fallback_activated']); |
|
68 | + } |
|
69 | 69 | } |
@@ -8,46 +8,46 @@ |
||
8 | 8 | */ |
9 | 9 | class PluginTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - public function test_plugin_is_loaded() |
|
12 | - { |
|
13 | - $active = get_option( 'active_plugins', array() ); |
|
14 | - $this->assertContains('mautic-wordpress/wpmautic.php', $active); |
|
15 | - |
|
16 | - $this->assertTrue(function_exists('wpmautic_option')); |
|
17 | - $this->assertTrue(function_exists('wpmautic_inject_script')); |
|
18 | - } |
|
19 | - |
|
20 | - public function test_action_loaded() |
|
21 | - { |
|
22 | - $this->assertTrue(false !== has_action('admin_menu', 'wpmautic_settings')); |
|
23 | - $this->assertTrue(false !== has_action('plugins_loaded', 'wpmautic_injector')); |
|
24 | - } |
|
25 | - |
|
26 | - public function test_filter_loaded() |
|
27 | - { |
|
28 | - $this->assertTrue(false !== has_filter('plugin_action_links', 'wpmautic_plugin_actions')); |
|
29 | - } |
|
30 | - |
|
31 | - public function test_settings_link_is_present() |
|
32 | - { |
|
33 | - $links = apply_filters('plugin_action_links', array(), 'mautic-wordpress/wpmautic.php'); |
|
34 | - |
|
35 | - $this->assertCount(1, $links); |
|
36 | - $this->assertContains('options-general.php?page=wpmautic', $links[0]); |
|
37 | - } |
|
38 | - |
|
39 | - public function test_option_page_is_loaded() |
|
40 | - { |
|
41 | - $current_user = get_current_user_id(); |
|
42 | - wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
|
43 | - |
|
44 | - $this->assertEmpty(menu_page_url('wpmautic', false)); |
|
45 | - wpmautic_settings(); |
|
46 | - $this->assertEquals( |
|
47 | - admin_url( 'options-general.php?page=wpmautic' ), |
|
48 | - menu_page_url('wpmautic', false) |
|
49 | - ); |
|
50 | - |
|
51 | - wp_set_current_user( $current_user ); |
|
52 | - } |
|
11 | + public function test_plugin_is_loaded() |
|
12 | + { |
|
13 | + $active = get_option( 'active_plugins', array() ); |
|
14 | + $this->assertContains('mautic-wordpress/wpmautic.php', $active); |
|
15 | + |
|
16 | + $this->assertTrue(function_exists('wpmautic_option')); |
|
17 | + $this->assertTrue(function_exists('wpmautic_inject_script')); |
|
18 | + } |
|
19 | + |
|
20 | + public function test_action_loaded() |
|
21 | + { |
|
22 | + $this->assertTrue(false !== has_action('admin_menu', 'wpmautic_settings')); |
|
23 | + $this->assertTrue(false !== has_action('plugins_loaded', 'wpmautic_injector')); |
|
24 | + } |
|
25 | + |
|
26 | + public function test_filter_loaded() |
|
27 | + { |
|
28 | + $this->assertTrue(false !== has_filter('plugin_action_links', 'wpmautic_plugin_actions')); |
|
29 | + } |
|
30 | + |
|
31 | + public function test_settings_link_is_present() |
|
32 | + { |
|
33 | + $links = apply_filters('plugin_action_links', array(), 'mautic-wordpress/wpmautic.php'); |
|
34 | + |
|
35 | + $this->assertCount(1, $links); |
|
36 | + $this->assertContains('options-general.php?page=wpmautic', $links[0]); |
|
37 | + } |
|
38 | + |
|
39 | + public function test_option_page_is_loaded() |
|
40 | + { |
|
41 | + $current_user = get_current_user_id(); |
|
42 | + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
|
43 | + |
|
44 | + $this->assertEmpty(menu_page_url('wpmautic', false)); |
|
45 | + wpmautic_settings(); |
|
46 | + $this->assertEquals( |
|
47 | + admin_url( 'options-general.php?page=wpmautic' ), |
|
48 | + menu_page_url('wpmautic', false) |
|
49 | + ); |
|
50 | + |
|
51 | + wp_set_current_user( $current_user ); |
|
52 | + } |
|
53 | 53 | } |
@@ -8,78 +8,78 @@ |
||
8 | 8 | */ |
9 | 9 | class PayloadTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - public function test_url_query_payload_deprecated_key() |
|
12 | - { |
|
13 | - $payload = wpmautic_get_url_query(); |
|
14 | - |
|
15 | - $this->assertArrayNotHasKey('url', $payload); |
|
16 | - $this->assertArrayNotHasKey('title', $payload); |
|
17 | - $this->assertArrayHasKey('page_url', $payload); |
|
18 | - $this->assertArrayHasKey('page_title', $payload); |
|
19 | - } |
|
20 | - |
|
21 | - public function test_url_query_payload_without_referer() |
|
22 | - { |
|
23 | - $base_url = 'http://example.org'; |
|
24 | - $this->go_to( $base_url ); |
|
25 | - |
|
26 | - $payload = wpmautic_get_url_query(); |
|
27 | - |
|
28 | - $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
29 | - |
|
30 | - $this->assertEquals($payload['page_url'], $base_url); |
|
31 | - $this->assertEquals($payload['page_title'], $title); |
|
32 | - $this->assertEquals($payload['language'], get_locale()); |
|
33 | - if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
34 | - $this->assertEquals($payload['referrer'], null); |
|
35 | - } else { |
|
36 | - $this->assertEquals($payload['referrer'], $base_url); |
|
37 | - } |
|
38 | - } |
|
39 | - |
|
40 | - public function test_url_query_payload_with_wp_referer() |
|
41 | - { |
|
42 | - if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
43 | - $this->markTestSkipped( 'wp_get_raw_referer function was introduced in WP 4.5' ); |
|
44 | - return; |
|
45 | - } |
|
46 | - |
|
47 | - $base_url = 'http://example.org'; |
|
48 | - $_REQUEST['_wp_http_referer'] = 'http://toto.org'; |
|
49 | - $this->go_to( $base_url ); |
|
50 | - |
|
51 | - $payload = wpmautic_get_url_query(); |
|
52 | - |
|
53 | - $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
54 | - |
|
55 | - $this->assertEquals($payload['page_url'], $base_url); |
|
56 | - $this->assertEquals($payload['page_title'], $title); |
|
57 | - $this->assertEquals($payload['language'], get_locale()); |
|
58 | - $this->assertEquals($payload['referrer'], 'http://toto.org'); |
|
59 | - |
|
60 | - unset($_REQUEST['_wp_http_referer']); |
|
61 | - } |
|
62 | - |
|
63 | - public function test_url_query_payload_with_server_referer() |
|
64 | - { |
|
65 | - if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
66 | - $this->markTestSkipped( 'wp_get_raw_referer function was introduced in WP 4.5' ); |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $base_url = 'http://example.org'; |
|
71 | - $_SERVER['HTTP_REFERER'] = 'http://toto.org'; |
|
72 | - $this->go_to( $base_url ); |
|
73 | - |
|
74 | - $payload = wpmautic_get_url_query(); |
|
75 | - |
|
76 | - $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
77 | - |
|
78 | - $this->assertEquals($payload['page_url'], $base_url); |
|
79 | - $this->assertEquals($payload['page_title'], $title); |
|
80 | - $this->assertEquals($payload['language'], get_locale()); |
|
81 | - $this->assertEquals($payload['referrer'], 'http://toto.org'); |
|
82 | - |
|
83 | - unset($_SERVER['HTTP_REFERER']); |
|
84 | - } |
|
11 | + public function test_url_query_payload_deprecated_key() |
|
12 | + { |
|
13 | + $payload = wpmautic_get_url_query(); |
|
14 | + |
|
15 | + $this->assertArrayNotHasKey('url', $payload); |
|
16 | + $this->assertArrayNotHasKey('title', $payload); |
|
17 | + $this->assertArrayHasKey('page_url', $payload); |
|
18 | + $this->assertArrayHasKey('page_title', $payload); |
|
19 | + } |
|
20 | + |
|
21 | + public function test_url_query_payload_without_referer() |
|
22 | + { |
|
23 | + $base_url = 'http://example.org'; |
|
24 | + $this->go_to( $base_url ); |
|
25 | + |
|
26 | + $payload = wpmautic_get_url_query(); |
|
27 | + |
|
28 | + $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
29 | + |
|
30 | + $this->assertEquals($payload['page_url'], $base_url); |
|
31 | + $this->assertEquals($payload['page_title'], $title); |
|
32 | + $this->assertEquals($payload['language'], get_locale()); |
|
33 | + if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
34 | + $this->assertEquals($payload['referrer'], null); |
|
35 | + } else { |
|
36 | + $this->assertEquals($payload['referrer'], $base_url); |
|
37 | + } |
|
38 | + } |
|
39 | + |
|
40 | + public function test_url_query_payload_with_wp_referer() |
|
41 | + { |
|
42 | + if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
43 | + $this->markTestSkipped( 'wp_get_raw_referer function was introduced in WP 4.5' ); |
|
44 | + return; |
|
45 | + } |
|
46 | + |
|
47 | + $base_url = 'http://example.org'; |
|
48 | + $_REQUEST['_wp_http_referer'] = 'http://toto.org'; |
|
49 | + $this->go_to( $base_url ); |
|
50 | + |
|
51 | + $payload = wpmautic_get_url_query(); |
|
52 | + |
|
53 | + $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
54 | + |
|
55 | + $this->assertEquals($payload['page_url'], $base_url); |
|
56 | + $this->assertEquals($payload['page_title'], $title); |
|
57 | + $this->assertEquals($payload['language'], get_locale()); |
|
58 | + $this->assertEquals($payload['referrer'], 'http://toto.org'); |
|
59 | + |
|
60 | + unset($_REQUEST['_wp_http_referer']); |
|
61 | + } |
|
62 | + |
|
63 | + public function test_url_query_payload_with_server_referer() |
|
64 | + { |
|
65 | + if ( version_compare( get_bloginfo('version'), '4.5', '<' ) ) { |
|
66 | + $this->markTestSkipped( 'wp_get_raw_referer function was introduced in WP 4.5' ); |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $base_url = 'http://example.org'; |
|
71 | + $_SERVER['HTTP_REFERER'] = 'http://toto.org'; |
|
72 | + $this->go_to( $base_url ); |
|
73 | + |
|
74 | + $payload = wpmautic_get_url_query(); |
|
75 | + |
|
76 | + $title = sprintf( "%s – %s", WP_TESTS_TITLE, get_option( 'blogdescription' ) ); |
|
77 | + |
|
78 | + $this->assertEquals($payload['page_url'], $base_url); |
|
79 | + $this->assertEquals($payload['page_title'], $title); |
|
80 | + $this->assertEquals($payload['language'], get_locale()); |
|
81 | + $this->assertEquals($payload['referrer'], 'http://toto.org'); |
|
82 | + |
|
83 | + unset($_SERVER['HTTP_REFERER']); |
|
84 | + } |
|
85 | 85 | } |
@@ -8,105 +8,105 @@ |
||
8 | 8 | */ |
9 | 9 | class ScriptInjectionTest extends WP_UnitTestCase |
10 | 10 | { |
11 | - private function renderRawPage($header = true, $footer = true) |
|
12 | - { |
|
13 | - $this->setOutputCallback(create_function('', '')); |
|
14 | - if (true === $header) { |
|
15 | - wp_head(); |
|
16 | - } |
|
17 | - if (true === $footer) { |
|
18 | - wp_footer(); |
|
19 | - } |
|
20 | - return $this->getActualOutput(); |
|
21 | - } |
|
22 | - |
|
23 | - public function setUp() |
|
24 | - { |
|
25 | - parent::setUp(); |
|
26 | - |
|
27 | - remove_action('wp_head', 'wpmautic_inject_script'); |
|
28 | - remove_action('wp_footer', 'wpmautic_inject_script'); |
|
29 | - remove_action('wp_footer', 'wpmautic_inject_noscript'); |
|
30 | - } |
|
31 | - |
|
32 | - public function test_script_is_not_injected_when_base_url_is_empty() |
|
33 | - { |
|
34 | - $output = $this->renderRawPage(); |
|
35 | - |
|
36 | - $this->assertNotContains(sprintf("(window,document,'script','/mtc.js','mt')"), $output); |
|
37 | - $this->assertNotContains("['MauticTrackingObject']", $output); |
|
38 | - $this->assertNotContains("mt('send', 'pageview')", $output); |
|
39 | - $this->assertNotContains("/mtracking.gif?d=", $output); |
|
40 | - } |
|
41 | - |
|
42 | - public function test_script_is_injected_with_valid_base_url() |
|
43 | - { |
|
44 | - $base_url = 'http://example.com'; |
|
45 | - update_option('wpmautic_options', array('base_url' => $base_url)); |
|
46 | - do_action('plugins_loaded'); |
|
47 | - |
|
48 | - $output = $this->renderRawPage(); |
|
49 | - |
|
50 | - $this->assertContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
51 | - $this->assertContains("['MauticTrackingObject']", $output); |
|
52 | - $this->assertContains("mt('send', 'pageview')", $output); |
|
53 | - $this->assertContains($base_url."/mtracking.gif?d=", $output); |
|
54 | - } |
|
55 | - |
|
56 | - public function test_script_is_not_injected_in_footer_by_default() |
|
57 | - { |
|
58 | - $base_url = 'http://example.com'; |
|
59 | - update_option('wpmautic_options', array('base_url' => $base_url)); |
|
60 | - do_action('plugins_loaded'); |
|
61 | - |
|
62 | - $output = $this->renderRawPage(false, true); |
|
63 | - |
|
64 | - $this->assertNotContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
65 | - $this->assertNotContains("['MauticTrackingObject']", $output); |
|
66 | - $this->assertNotContains("mt('send', 'pageview')", $output); |
|
67 | - |
|
68 | - //Fallback activated and <noscript> is always injected in footer ! |
|
69 | - $this->assertContains(sprintf("%s/mtracking.gif?d=", $base_url), $output); |
|
70 | - } |
|
71 | - |
|
72 | - public function test_script_is_injected_in_footer_when_requested() |
|
73 | - { |
|
74 | - $base_url = 'http://example.com'; |
|
75 | - update_option('wpmautic_options', array('base_url' => $base_url, 'script_location' => 'footer')); |
|
76 | - do_action('plugins_loaded'); |
|
77 | - |
|
78 | - $output = $this->renderRawPage(false, true); |
|
79 | - |
|
80 | - $this->assertContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
81 | - $this->assertContains("['MauticTrackingObject']", $output); |
|
82 | - $this->assertContains("mt('send', 'pageview')", $output); |
|
83 | - $this->assertContains(sprintf("%s/mtracking.gif?d=", $base_url), $output); |
|
84 | - } |
|
85 | - |
|
86 | - public function test_tracking_image_is_not_injected_when_disabled() |
|
87 | - { |
|
88 | - $base_url = 'http://example.com'; |
|
89 | - update_option('wpmautic_options', array( |
|
90 | - 'base_url' => $base_url, |
|
91 | - 'fallback_activated' => false |
|
92 | - )); |
|
93 | - do_action('plugins_loaded'); |
|
94 | - |
|
95 | - $output = $this->renderRawPage(); |
|
96 | - |
|
97 | - $this->assertNotContains("/mtracking.gif?d=", $output); |
|
98 | - } |
|
99 | - |
|
100 | - public function test_tracking_image_payload_is_valid() |
|
101 | - { |
|
102 | - $base_url = 'http://example.com'; |
|
103 | - $this->go_to( $base_url ); |
|
104 | - update_option('wpmautic_options', array('base_url' => $base_url)); |
|
105 | - do_action('plugins_loaded'); |
|
106 | - |
|
107 | - $output = $this->renderRawPage(); |
|
108 | - |
|
109 | - $payload = rawurlencode( base64_encode( serialize( wpmautic_get_url_query() ) ) ); |
|
110 | - $this->assertContains(sprintf("%s/mtracking.gif?d=%s", $base_url, $payload), $output); |
|
111 | - } |
|
11 | + private function renderRawPage($header = true, $footer = true) |
|
12 | + { |
|
13 | + $this->setOutputCallback(create_function('', '')); |
|
14 | + if (true === $header) { |
|
15 | + wp_head(); |
|
16 | + } |
|
17 | + if (true === $footer) { |
|
18 | + wp_footer(); |
|
19 | + } |
|
20 | + return $this->getActualOutput(); |
|
21 | + } |
|
22 | + |
|
23 | + public function setUp() |
|
24 | + { |
|
25 | + parent::setUp(); |
|
26 | + |
|
27 | + remove_action('wp_head', 'wpmautic_inject_script'); |
|
28 | + remove_action('wp_footer', 'wpmautic_inject_script'); |
|
29 | + remove_action('wp_footer', 'wpmautic_inject_noscript'); |
|
30 | + } |
|
31 | + |
|
32 | + public function test_script_is_not_injected_when_base_url_is_empty() |
|
33 | + { |
|
34 | + $output = $this->renderRawPage(); |
|
35 | + |
|
36 | + $this->assertNotContains(sprintf("(window,document,'script','/mtc.js','mt')"), $output); |
|
37 | + $this->assertNotContains("['MauticTrackingObject']", $output); |
|
38 | + $this->assertNotContains("mt('send', 'pageview')", $output); |
|
39 | + $this->assertNotContains("/mtracking.gif?d=", $output); |
|
40 | + } |
|
41 | + |
|
42 | + public function test_script_is_injected_with_valid_base_url() |
|
43 | + { |
|
44 | + $base_url = 'http://example.com'; |
|
45 | + update_option('wpmautic_options', array('base_url' => $base_url)); |
|
46 | + do_action('plugins_loaded'); |
|
47 | + |
|
48 | + $output = $this->renderRawPage(); |
|
49 | + |
|
50 | + $this->assertContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
51 | + $this->assertContains("['MauticTrackingObject']", $output); |
|
52 | + $this->assertContains("mt('send', 'pageview')", $output); |
|
53 | + $this->assertContains($base_url."/mtracking.gif?d=", $output); |
|
54 | + } |
|
55 | + |
|
56 | + public function test_script_is_not_injected_in_footer_by_default() |
|
57 | + { |
|
58 | + $base_url = 'http://example.com'; |
|
59 | + update_option('wpmautic_options', array('base_url' => $base_url)); |
|
60 | + do_action('plugins_loaded'); |
|
61 | + |
|
62 | + $output = $this->renderRawPage(false, true); |
|
63 | + |
|
64 | + $this->assertNotContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
65 | + $this->assertNotContains("['MauticTrackingObject']", $output); |
|
66 | + $this->assertNotContains("mt('send', 'pageview')", $output); |
|
67 | + |
|
68 | + //Fallback activated and <noscript> is always injected in footer ! |
|
69 | + $this->assertContains(sprintf("%s/mtracking.gif?d=", $base_url), $output); |
|
70 | + } |
|
71 | + |
|
72 | + public function test_script_is_injected_in_footer_when_requested() |
|
73 | + { |
|
74 | + $base_url = 'http://example.com'; |
|
75 | + update_option('wpmautic_options', array('base_url' => $base_url, 'script_location' => 'footer')); |
|
76 | + do_action('plugins_loaded'); |
|
77 | + |
|
78 | + $output = $this->renderRawPage(false, true); |
|
79 | + |
|
80 | + $this->assertContains(sprintf("(window,document,'script','{$base_url}/mtc.js','mt')"), $output); |
|
81 | + $this->assertContains("['MauticTrackingObject']", $output); |
|
82 | + $this->assertContains("mt('send', 'pageview')", $output); |
|
83 | + $this->assertContains(sprintf("%s/mtracking.gif?d=", $base_url), $output); |
|
84 | + } |
|
85 | + |
|
86 | + public function test_tracking_image_is_not_injected_when_disabled() |
|
87 | + { |
|
88 | + $base_url = 'http://example.com'; |
|
89 | + update_option('wpmautic_options', array( |
|
90 | + 'base_url' => $base_url, |
|
91 | + 'fallback_activated' => false |
|
92 | + )); |
|
93 | + do_action('plugins_loaded'); |
|
94 | + |
|
95 | + $output = $this->renderRawPage(); |
|
96 | + |
|
97 | + $this->assertNotContains("/mtracking.gif?d=", $output); |
|
98 | + } |
|
99 | + |
|
100 | + public function test_tracking_image_payload_is_valid() |
|
101 | + { |
|
102 | + $base_url = 'http://example.com'; |
|
103 | + $this->go_to( $base_url ); |
|
104 | + update_option('wpmautic_options', array('base_url' => $base_url)); |
|
105 | + do_action('plugins_loaded'); |
|
106 | + |
|
107 | + $output = $this->renderRawPage(); |
|
108 | + |
|
109 | + $payload = rawurlencode( base64_encode( serialize( wpmautic_get_url_query() ) ) ); |
|
110 | + $this->assertContains(sprintf("%s/mtracking.gif?d=%s", $base_url, $payload), $output); |
|
111 | + } |
|
112 | 112 | } |