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