Révision ed9a13f1
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/sites/all/modules/feeds/tests/http_request.test | ||
---|---|---|
9 | 9 |
* Tests for the http library. |
10 | 10 |
*/ |
11 | 11 |
class FeedsHTTPRequestTestCase extends FeedsUnitTestHelper { |
12 |
|
|
13 |
/** |
|
14 |
* {@inheritdoc} |
|
15 |
*/ |
|
12 | 16 |
public static function getInfo() { |
13 | 17 |
return array( |
14 | 18 |
'name' => 'HTTP library', |
... | ... | |
17 | 21 |
); |
18 | 22 |
} |
19 | 23 |
|
24 |
/** |
|
25 |
* {@inheritdoc} |
|
26 |
*/ |
|
20 | 27 |
public function setUp() { |
21 | 28 |
parent::setUp(); |
22 | 29 |
feeds_include_library('http_request.inc', 'http_request'); |
... | ... | |
51 | 58 |
$this->assertEqual($links[0], 'http://example.com/rss.xml'); |
52 | 59 |
} |
53 | 60 |
|
61 |
/** |
|
62 |
* Tests fetching data from a protected directory. |
|
63 |
*/ |
|
64 |
public function testProtectedPages() { |
|
65 |
// Create a directory and put a file in it. |
|
66 |
$dir = 'public://feeds-protected'; |
|
67 |
file_prepare_directory($dir, FILE_CREATE_DIRECTORY); |
|
68 |
file_put_contents($dir . '/content.txt', 'A protected document'); |
|
69 |
|
|
70 |
// Create .htpasswd and .htaccess files. |
|
71 |
file_put_contents($dir . '/.htpasswd', 'Morticia:$apr1$s3SZUBCe$loi5XqSMHJ9CRfsY9GzLW/'); |
|
72 |
$htaccess = "AuthType Basic\nAuthName \"Restricted area\"\nAuthUserFile !path\nrequire valid-user"; |
|
73 |
$htaccess = strtr($htaccess, array( |
|
74 |
'!path' => drupal_realpath($dir . '/.htpasswd'), |
|
75 |
)); |
|
76 |
file_put_contents($dir . '/.htaccess', $htaccess); |
|
77 |
|
|
78 |
// Create url to file. |
|
79 |
$url = file_create_url($dir . '/content.txt'); |
|
80 |
|
|
81 |
// Try to access the file without username/password. |
|
82 |
$result = feeds_http_request($url, array( |
|
83 |
'cache_http_result' => FALSE, |
|
84 |
)); |
|
85 |
// Assert that it was forbidden. |
|
86 |
$this->assertEqual(401, $result->code); |
|
87 |
$this->assertNotEqual('A protected document', $result->data); |
|
88 |
|
|
89 |
// Now access the same with username/password. |
|
90 |
$result = feeds_http_request($url, array( |
|
91 |
'username' => 'Morticia', |
|
92 |
'password' => 'mort', |
|
93 |
'cache_http_result' => FALSE, |
|
94 |
)); |
|
95 |
// And assert that this time the request was successful. |
|
96 |
$this->assertEqual(200, $result->code); |
|
97 |
$this->assertEqual('A protected document', $result->data); |
|
98 |
} |
|
99 |
|
|
54 | 100 |
/** |
55 | 101 |
* Tests http_request_create_absolute_url(). |
56 | 102 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules