Completed
Push — test/testing-packages-soft-wor... ( cf0a87 )
by
unknown
76:36 queued 69:22
created

SoftWordPressTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 81.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 54
loc 66
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_url() 54 54 1
A test_options() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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