1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains tests for WP_Hydra::setup_content() |
4
|
|
|
* |
5
|
|
|
* @package wp-hydra |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests for WP_Hydra::setup_content() |
10
|
|
|
*/ |
11
|
|
|
class WpHydraSetupContentTest extends WP_UnitTestCase { |
12
|
|
|
/** |
13
|
|
|
* Test setup |
14
|
|
|
*/ |
15
|
|
|
public function setUp() { |
16
|
|
|
$this->wp_hydra = $this->getMockBuilder( 'WP_Hydra' )->disableOriginalConstructor()->setMethods( array( 'setup_domain' ) )->getMock(); |
17
|
|
|
|
18
|
|
|
$this->domain = 'https://foobar.com'; |
19
|
|
|
|
20
|
|
|
$this->wp_hydra->expects( $this->any() ) |
21
|
|
|
->method( 'setup_domain' ) |
22
|
|
|
->will( $this->returnValue( $this->domain ) ); |
23
|
|
|
|
24
|
|
|
remove_all_filters( 'option_home', 1 ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Test teardown |
29
|
|
|
*/ |
30
|
|
|
public function tearDown() { |
31
|
|
|
unset( $this->wp_hydra ); |
32
|
|
|
unset( $this->domain ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test occurences in the beginning. |
37
|
|
|
* |
38
|
|
|
* @covers WP_Hydra::setup_content |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function testOccurencesInTheBeginning() { |
|
|
|
|
41
|
|
|
$content = 'https://example.org/ foo bar '; |
42
|
|
|
$expected = $this->domain . '/ foo bar '; |
43
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
44
|
|
|
|
45
|
|
|
$this->assertSame( $expected, $actual ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Test occurences in the middle. |
50
|
|
|
* |
51
|
|
|
* @covers WP_Hydra::setup_content |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testOccurencesInTheMiddle() { |
|
|
|
|
54
|
|
|
$content = 'helloWorld https://example.org/ foo bar '; |
55
|
|
|
$expected = 'helloWorld ' . $this->domain . '/ foo bar '; |
56
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
57
|
|
|
|
58
|
|
|
$this->assertSame( $expected, $actual ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Test occurences in the end. |
63
|
|
|
* |
64
|
|
|
* @covers WP_Hydra::setup_content |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
public function testOccurencesInTheEnd() { |
|
|
|
|
67
|
|
|
$content = 'helloWorld https://example.org/'; |
68
|
|
|
$expected = 'helloWorld ' . $this->domain . '/'; |
69
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
70
|
|
|
|
71
|
|
|
$this->assertSame( $expected, $actual ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Test multiple occurences. |
76
|
|
|
* |
77
|
|
|
* @covers WP_Hydra::setup_content |
78
|
|
|
*/ |
79
|
|
|
public function testMultipleOccurences() { |
80
|
|
|
$content = 'https://example.org/ helloWorld https://example.org/ foo bar https://example.org/'; |
81
|
|
|
$expected = $this->domain . '/ helloWorld ' . $this->domain . '/ foo bar ' . $this->domain . '/'; |
82
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
83
|
|
|
|
84
|
|
|
$this->assertSame( $expected, $actual ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Test occurences in an image. |
89
|
|
|
* |
90
|
|
|
* @covers WP_Hydra::setup_content |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function testOccurencesInAnImage() { |
|
|
|
|
93
|
|
|
$content = '<img src="https://example.org/wp-content/uploads/2012/12/test.jpg" width="640" height="480" alt="" />'; |
94
|
|
|
$expected = '<img src="' . $this->domain . '/wp-content/uploads/2012/12/test.jpg" width="640" height="480" alt="" />'; |
95
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
96
|
|
|
|
97
|
|
|
$this->assertSame( $expected, $actual ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Test occurences in a link. |
102
|
|
|
* |
103
|
|
|
* @covers WP_Hydra::setup_content |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function testOccurencesInALink() { |
|
|
|
|
106
|
|
|
$content = '<a href="https://example.org/foo/bar/">Test</a>'; |
107
|
|
|
$expected = '<a href="' . $this->domain . '/foo/bar/">Test</a>'; |
108
|
|
|
$actual = $this->wp_hydra->setup_content( $content ); |
109
|
|
|
|
110
|
|
|
$this->assertSame( $expected, $actual ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
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.