Completed
Push — renovate/jsdom-16.x ( 553f2a...6948b4 )
by
unknown
77:15 queued 59:05
created

RedirectTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_get_url() 0 37 1
1
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2
3
namespace Automattic\Jetpack;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Test Redirect class
9
 */
10
class RedirectTest extends TestCase {
11
12
	/**
13
	 * Basic tests to get_url method.
14
	 */
15
	public function test_get_url() {
16
17
		$url = Redirect::get_url( 'simple' );
18
		$this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url );
19
20
		// Test invalid parameter.
21
		$url = Redirect::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 = Redirect::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 = Redirect::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 = Redirect::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 = Redirect::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 = Redirect::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 = Redirect::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
	}
52
53
}
54