1
|
|
|
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing |
2
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Test class |
9
|
|
|
*/ |
10
|
|
|
class SoftWordPressTest extends TestCase { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Basic tests to get_url method. |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
public function test_get_url() { |
16
|
|
|
|
17
|
|
|
$url = Soft_Wp::get_url( 'simple' ); |
18
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
19
|
|
|
|
20
|
|
|
// Test invalid parameter. |
21
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'invalid' => 'value' ) ); |
22
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
23
|
|
|
|
24
|
|
|
// Test path. |
25
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'path' => 'value' ) ); |
26
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=value', $url ); |
27
|
|
|
|
28
|
|
|
// Test path special chars. |
29
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'path' => 'weird value!' ) ); |
30
|
|
|
$v = rawurlencode( 'weird value!' ); |
31
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=' . $v, $url ); |
32
|
|
|
|
33
|
|
|
// Test query. |
34
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'query' => 'value' ) ); |
35
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=value', $url ); |
36
|
|
|
|
37
|
|
|
// Test query special chars. |
38
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'query' => 'key=value&key2=value2' ) ); |
39
|
|
|
$v = rawurlencode( 'key=value&key2=value2' ); |
40
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=' . $v, $url ); |
41
|
|
|
|
42
|
|
|
// Test anchor. |
43
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'value' ) ); |
44
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=value', $url ); |
45
|
|
|
|
46
|
|
|
// Test anchor special chars. |
47
|
|
|
$url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'key=value&key2=value2' ) ); |
48
|
|
|
$v = rawurlencode( 'key=value&key2=value2' ); |
49
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=' . $v, $url ); |
50
|
|
|
|
51
|
|
|
// Test informing URL. |
52
|
|
|
$url = Soft_Wp::get_url( 'https://wordpress.com/support' ); |
53
|
|
|
$v = rawurlencode( 'https://wordpress.com/support' ); |
54
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?url=' . $v . '&site=example.org', $url ); |
55
|
|
|
|
56
|
|
|
// Test URL and query. |
57
|
|
|
$url = Soft_Wp::get_url( 'https://wordpress.com/support', array( 'query' => 'key=value&key2=value2' ) ); |
58
|
|
|
$v = rawurlencode( 'key=value&key2=value2' ); |
59
|
|
|
$v_url = rawurlencode( 'https://wordpress.com/support' ); |
60
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
61
|
|
|
|
62
|
|
|
// Test URL and query, discarding info from url. |
63
|
|
|
$url = Soft_Wp::get_url( 'https://wordpress.com/support?this=that#super', array( 'query' => 'key=value&key2=value2' ) ); |
64
|
|
|
$v = rawurlencode( 'key=value&key2=value2' ); |
65
|
|
|
$v_url = rawurlencode( 'https://wordpress.com/support' ); |
66
|
|
|
$this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function test_options() { |
71
|
|
|
Soft_Wp::store( 'testing', 123 ); |
72
|
|
|
$this->assertEquals( 123, Soft_Wp::get( 'testing' ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|