1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package wpmautic\tests |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Ensure that payload data are valid in the current context |
8
|
|
|
*/ |
9
|
|
|
class PayloadTest extends WP_UnitTestCase |
|
|
|
|
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
|
|
View Code Duplication |
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
|
|
View Code Duplication |
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
|
|
|
} |
86
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.