Completed
Pull Request — master (#15)
by Marin
01:29
created

WpHydraSetupDomainTest::testWithDifferentDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
class WpHydraSetupDomainTest extends WP_UnitTestCase {
4
5
	public function setUp() {
6
		$this->wp_hydra = $this->getMockBuilder('WP_Hydra')->setMethods(null)->getMock();
7
	}
8
9
	public function tearDown() {
10
		unset( $this->wp_hydra );
11
	}
12
13
	/**
14
	 * @covers WP_Hydra::setup_domain
15
	 */
16
	public function testWithWrongURL() {
17
		$url = 'foo/com';
18
19
		$result = $this->wp_hydra->setup_domain( $url );
20
21
		$this->assertSame( $url, $result );
22
	}
23
24
	/**
25
	 * @covers WP_Hydra::setup_domain
26
	 */
27 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...
28
		$original_host = $_SERVER['HTTP_HOST'];
29
		unset($_SERVER['HTTP_HOST']);
30
31
		$url = 'http://example.xyz/lorem-ipsum/';
32
33
		$result = $this->wp_hydra->setup_domain( $url );
34
35
		$this->assertSame( $url, $result );
36
37
		$_SERVER['HTTP_HOST'] = $original_host;
38
	}
39
40
	/**
41
	 * @covers WP_Hydra::setup_domain
42
	 */
43 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...
44
		$original_host = $_SERVER['HTTP_HOST'];
45
46
		$_SERVER['HTTP_HOST'] = 'example.com';
47
		$url = 'http://example.com/lorem-ipsum/';
48
49
		$result = $this->wp_hydra->setup_domain( $url );
50
51
		$this->assertSame( $url, $result );
52
53
		$_SERVER['HTTP_HOST'] = $original_host;
54
	}
55
56
	/**
57
	 * @covers WP_Hydra::setup_domain
58
	 */
59
	public function testWithDifferentDomain() {
60
		$original_host = $_SERVER['HTTP_HOST'];
61
62
		$current_domain = $_SERVER['HTTP_HOST'] = 'foobar.com';
63
		$original_domain = 'example.com';
64
		$url = 'http://example.com/lorem-ipsum/';
65
		$exposed_instance = $this->getMockBuilder('WP_Hydra_Exposed')->setMethods(null)->getMock();
66
67
		$expected = $exposed_instance->replace_domain_exposed( $url, $original_domain, $current_domain );
68
		$actual = $this->wp_hydra->setup_domain( $url );
69
70
		$this->assertSame( $expected, $actual );
71
72
		$_SERVER['HTTP_HOST'] = $original_host;
73
	}
74
75
}
76
77
class WP_Hydra_Exposed extends WP_Hydra {
78
	public function replace_domain_exposed( $url, $original_domain, $current_domain ) {
79
		return $this->replace_domain( $url, $original_domain, $current_domain );
80
	}
81
}