Completed
Push — fix/videopress-aspect-ratio ( 254a53...ebcf36 )
by Jeremy
11:10 queued 03:02
created

RedirectTest::tear_down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * File for testing Redirects.
4
 *
5
 * @package Automattic/jetpack-redirect
6
 */
7
8
namespace Automattic\Jetpack;
9
10
use Brain\Monkey;
11
use Brain\Monkey\Functions;
12
use PHPUnit\Framework\TestCase;
13
14
/**
15
 * Test Redirect class
16
 */
17
class RedirectTest extends TestCase {
18
19
	/**
20
	 * Test setup.
21
	 *
22
	 * @before
23
	 */
24
	public function set_up() {
25
		Monkey\setUp();
26
		$this->status = new Status();
27
	}
28
29
	/**
30
	 * Test teardown.
31
	 *
32
	 * @after
33
	 */
34
	public function tear_down() {
35
		Monkey\tearDown();
36
	}
37
38
	/**
39
	 * Basic tests to get_url method.
40
	 */
41
	public function test_get_url() {
42
		Functions\when( 'home_url' )->justReturn( 'https://example.org' );
43
44
		$url = Redirect::get_url( 'simple' );
45
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org', $url );
46
47
		// Test invalid parameter.
48
		$url = Redirect::get_url( 'simple', array( 'invalid' => 'value' ) );
49
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org', $url );
50
51
		// Test path.
52
		$url = Redirect::get_url( 'simple', array( 'path' => 'value' ) );
53
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&path=value', $url );
54
55
		// Test path special chars.
56
		$url = Redirect::get_url( 'simple', array( 'path' => 'weird value!' ) );
57
		$v   = rawurlencode( 'weird value!' );
58
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&path=' . $v, $url );
59
60
		// Test query.
61
		$url = Redirect::get_url( 'simple', array( 'query' => 'value' ) );
62
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&query=value', $url );
63
64
		// Test query special chars.
65
		$url = Redirect::get_url( 'simple', array( 'query' => 'key=value&key2=value2' ) );
66
		$v   = rawurlencode( 'key=value&key2=value2' );
67
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&query=' . $v, $url );
68
69
		// Test anchor.
70
		$url = Redirect::get_url( 'simple', array( 'anchor' => 'value' ) );
71
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&anchor=value', $url );
72
73
		// Test anchor special chars.
74
		$url = Redirect::get_url( 'simple', array( 'anchor' => 'key=value&key2=value2' ) );
75
		$v   = rawurlencode( 'key=value&key2=value2' );
76
		$this->assertEquals( 'https://jetpack.com/redirect/?source=simple&site=example.org&anchor=' . $v, $url );
77
78
		// Test informing URL.
79
		$url = Redirect::get_url( 'https://wordpress.com/support' );
80
		$v   = rawurlencode( 'https://wordpress.com/support' );
81
		$this->assertEquals( 'https://jetpack.com/redirect/?url=' . $v . '&site=example.org', $url );
82
83
		// Test URL and query.
84
		$url   = Redirect::get_url( 'https://wordpress.com/support', array( 'query' => 'key=value&key2=value2' ) );
85
		$v     = rawurlencode( 'key=value&key2=value2' );
86
		$v_url = rawurlencode( 'https://wordpress.com/support' );
87
		$this->assertEquals( 'https://jetpack.com/redirect/?url=' . $v_url . '&site=example.org&query=' . $v, $url );
88
89
		// Test URL and query, discarding info from url.
90
		$url   = Redirect::get_url( 'https://wordpress.com/support?this=that#super', array( 'query' => 'key=value&key2=value2' ) );
91
		$v     = rawurlencode( 'key=value&key2=value2' );
92
		$v_url = rawurlencode( 'https://wordpress.com/support' );
93
		$this->assertEquals( 'https://jetpack.com/redirect/?url=' . $v_url . '&site=example.org&query=' . $v, $url );
94
95
	}
96
97
}
98