Completed
Pull Request — master (#15)
by Marin
03:51 queued 02:28
created

WpHydraSetupDomainTest::testWithTheSameDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Contains tests for WP_Hydra::setup_domain()
4
 *
5
 * @package wp-hydra
6
 */
7
8
/**
9
 * Tests for WP_Hydra::setup_domain()
10
 */
11
class WpHydraSetupDomainTest extends WP_UnitTestCase {
12
	/**
13
	 * Test setup
14
	 */
15
	public function setUp() {
16
		$this->wp_hydra = $this->getMockBuilder( 'WP_Hydra' )->setMethods( null )->getMock();
17
	}
18
19
	/**
20
	 * Test teardown
21
	 */
22
	public function tearDown() {
23
		unset( $this->wp_hydra );
24
	}
25
26
	/**
27
	 * Test with a wrong URL.
28
	 *
29
	 * @covers WP_Hydra::setup_domain
30
	 */
31
	public function testWithWrongURL() {
32
		$url = 'foo/com';
33
34
		$result = $this->wp_hydra->setup_domain( $url );
35
36
		$this->assertSame( $url, $result );
37
	}
38
39
	/**
40
	 * Test with a no host specified.
41
	 *
42
	 * @covers WP_Hydra::setup_domain
43
	 */
44 View Code Duplication
	public function testWithNoHost() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
		$original_host = $_SERVER['HTTP_HOST'];
46
		unset( $_SERVER['HTTP_HOST'] );
47
48
		$url = 'http://example.xyz/lorem-ipsum/';
49
50
		$result = $this->wp_hydra->setup_domain( $url );
51
52
		$this->assertSame( $url, $result );
53
54
		$_SERVER['HTTP_HOST'] = $original_host;
55
	}
56
57
	/**
58
	 * Test with the same domain.
59
	 *
60
	 * @covers WP_Hydra::setup_domain
61
	 */
62 View Code Duplication
	public function testWithTheSameDomain() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
		$original_host = $_SERVER['HTTP_HOST'];
64
65
		$_SERVER['HTTP_HOST'] = 'example.com';
66
		$url                  = 'http://example.com/lorem-ipsum/';
67
68
		$result = $this->wp_hydra->setup_domain( $url );
69
70
		$this->assertSame( $url, $result );
71
72
		$_SERVER['HTTP_HOST'] = $original_host;
73
	}
74
75
	/**
76
	 * Test with a different domain.
77
	 *
78
	 * @covers WP_Hydra::setup_domain
79
	 */
80
	public function testWithDifferentDomain() {
81
		$original_host        = $_SERVER['HTTP_HOST'];
82
		$current_domain       = 'foobar.com';
83
		$_SERVER['HTTP_HOST'] = 'foobar.com';
84
		$original_domain      = 'example.com';
85
		$url                  = 'http://example.com/lorem-ipsum/';
86
		$exposed_instance     = $this->getMockBuilder( 'WP_Hydra_Exposed' )->setMethods( null )->getMock();
87
88
		$expected = $exposed_instance->replace_domain_exposed( $url, $original_domain, $current_domain );
89
		$actual   = $this->wp_hydra->setup_domain( $url );
90
91
		$this->assertSame( $expected, $actual );
92
93
		$_SERVER['HTTP_HOST'] = $original_host;
94
	}
95
96
}
97
98
/**
99
 * Class that exposes the private WP_Hydra::replace_domain() method
100
 */
101
class WP_Hydra_Exposed extends WP_Hydra {
102
	/**
103
	 * Exposes the private WP_Hydra::replace_domain() method.
104
	 *
105
	 * @param string $url The domain.
106
	 * @param string $original_domain The original domain.
107
	 * @param string $current_domain The current domain.
108
	 * @return string String with domain replaced.
109
	 */
110
	public function replace_domain_exposed( $url, $original_domain, $current_domain ) {
111
		return $this->replace_domain( $url, $original_domain, $current_domain );
112
	}
113
}
114