| 1 |
<?php
|
| 2 |
// $Id: atom.test,v 1.4 2009/09/21 17:21:32 davereid Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Unit tests for the atom module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
class AtomFunctionalTest extends DrupalWebTestCase {
|
| 10 |
public static function getInfo() {
|
| 11 |
return array(
|
| 12 |
'name' => 'Atom functionality',
|
| 13 |
'description' => 'Functional tests for the Atom module.',
|
| 14 |
'group' => 'Atom',
|
| 15 |
);
|
| 16 |
}
|
| 17 |
|
| 18 |
function setUp() {
|
| 19 |
parent::setUp('atom');
|
| 20 |
$this->denied_user = $this->drupalCreateUser(array());
|
| 21 |
$this->normal_user = $this->drupalCreateUser(array('access content'));
|
| 22 |
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'administer atom'));
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Test access to the Atom feeds.
|
| 27 |
*/
|
| 28 |
function testAtomAccess() {
|
| 29 |
$this->drupalLogin($this->denied_user);
|
| 30 |
$this->drupalGet('atom.xml');
|
| 31 |
$this->assertResponse(403);
|
| 32 |
$this->drupalGet('');
|
| 33 |
$this->assertNoRaw('application/atom+xml');
|
| 34 |
|
| 35 |
$this->drupalLogin($this->normal_user);
|
| 36 |
$this->drupalGet('atom.xml');
|
| 37 |
$this->assertResponse(200);
|
| 38 |
$this->drupalGet('');
|
| 39 |
$this->assertRaw('application/atom+xml');
|
| 40 |
|
| 41 |
$this->assertValidAtom('atom.xml');
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Assert that an Atom feed is valid as checked by the W3C Validator.
|
| 46 |
*/
|
| 47 |
protected function assertValidAtom($url = NULL, $options = array()) {
|
| 48 |
if (isset($url)) {
|
| 49 |
$this->drupalGet($url, $options);
|
| 50 |
}
|
| 51 |
|
| 52 |
$request = drupal_http_request('http://validator.w3.org/feed/check.cgi', array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'method' => 'POST', 'data' => "rawdata=" . urlencode($this->drupalGetContent()) . "&manual=true"));
|
| 53 |
$this->drupalSetContent($request->data);
|
| 54 |
|
| 55 |
preg_match_all('%<span class="message">.*</span>.*\[<a .* href=".*">help</a>\]%', $request->data, $warnings);
|
| 56 |
foreach ($warnings[0] as $warning) {
|
| 57 |
$warning = strip_tags($warning, '<a>');
|
| 58 |
$warning = str_replace('href="docs', 'href="http://validator.w3.org/feed/docs', $warning);
|
| 59 |
$this->error($warning);
|
| 60 |
}
|
| 61 |
|
| 62 |
return $this->assertText('This is a valid Atom 1.0 feed.', "Atom 1.0 feed $url validated.");
|
| 63 |
}
|
| 64 |
}
|