1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @filesource ExtractUrlTest.php |
5
|
|
|
* @created 16.02.2016 |
6
|
|
|
* @package chillerlan\TinyCurlTest |
7
|
|
|
* @author Smiley <[email protected]> |
8
|
|
|
* @copyright 2016 Smiley |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace chillerlan\TinyCurlTest; |
13
|
|
|
|
14
|
|
|
use chillerlan\TinyCurl\Request; |
15
|
|
|
use chillerlan\TinyCurl\RequestOptions; |
16
|
|
|
|
17
|
|
|
class ExtractUrlTest extends \PHPUnit_Framework_TestCase{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \chillerlan\TinyCurl\Request |
21
|
|
|
*/ |
22
|
|
|
protected $requestWithCA; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \chillerlan\TinyCurl\Request |
26
|
|
|
*/ |
27
|
|
|
protected $requestNoCA; |
28
|
|
|
|
29
|
|
View Code Duplication |
protected function setUp(){ |
|
|
|
|
30
|
|
|
$co = [CURLOPT_FOLLOWLOCATION => false]; |
31
|
|
|
|
32
|
|
|
$o1 = new RequestOptions; |
33
|
|
|
$o1->curl_options = $co; |
34
|
|
|
$o1->ca_info = __DIR__.'/test-cacert.pem'; |
35
|
|
|
$this->requestWithCA = new Request($o1); |
36
|
|
|
|
37
|
|
|
$o2 = new RequestOptions; |
38
|
|
|
$o2->curl_options = $co; |
39
|
|
|
$this->requestNoCA = new Request($o2); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function shortURLDataProvider(){ |
43
|
|
|
return [ |
44
|
|
|
[ |
45
|
|
|
[ |
46
|
|
|
'https://t.co/YK4EuyMbl3', |
47
|
|
|
'http://buff.ly/20TJh3q', |
48
|
|
|
'http://www.ebay.com/sch/gillianandersoncharity/m.html?utm_content=buffer5675f&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer', |
49
|
|
|
] |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
[ |
53
|
|
|
'https://t.co/ZSS6nVOcVp', // i wonder how long twitter will store this URL since the test tweet has been deleted |
54
|
|
|
'http://bit.ly/1oesmr8', |
55
|
|
|
'http://tinyurl.com/jvc5y98', |
56
|
|
|
'https://api.guildwars2.com/v2/build', |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
[ |
61
|
|
|
'http://curl.haxx.se/ca/cacert.pem', |
62
|
|
|
'https://curl.haxx.se/ca/cacert.pem', |
63
|
|
|
|
64
|
|
|
// grabbing the body is perhaps a little too greedy... |
65
|
|
|
# 'http://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', |
66
|
|
|
# 'http://mozilla.org/MPL/2.0/', |
67
|
|
|
# 'https://www.mozilla.org/MPL/2.0/', |
68
|
|
|
# 'https://www.mozilla.org/en-US/MPL/2.0/', |
69
|
|
|
# 'http://html5shim.googlecode.com/svn/trunk/html5.js', |
70
|
|
|
], |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @dataProvider shortURLDataProvider |
77
|
|
|
*/ |
78
|
|
|
public function testExtractShortUrlWithCA($expected){ |
79
|
|
|
$this->assertEquals($expected, $this->requestWithCA->extractShortUrl($expected[0])); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @dataProvider shortURLDataProvider |
84
|
|
|
*/ |
85
|
|
|
public function testExtractShortUrlNoCA($expected){ |
86
|
|
|
$this->assertEquals($expected, $this->requestNoCA->extractShortUrl($expected[0])); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
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.