Merge pull request #1 from tractorcow/pulls/description

API Add description for response code to report
This commit is contained in:
Sean Harvey 2014-08-13 11:08:56 +12:00
commit d9e1b998d7
3 changed files with 35 additions and 4 deletions

View File

@ -27,7 +27,7 @@ class BrokenExternalLink extends DataObject {
public static $summary_fields = array(
'Page.Title' => 'Page',
'HTTPCode' => 'HTTP Code',
'HTTPCodeDescription' => 'HTTP Code',
'Created' => 'Created'
);
@ -35,15 +35,36 @@ class BrokenExternalLink extends DataObject {
'HTTPCode' => array('title' => 'HTTP Code')
);
function canEdit($member = false) {
public function canEdit($member = false) {
return false;
}
function canView($member = false) {
public function canView($member = false) {
$member = $member ? $member : Member::currentUser();
$codes = array('content-authors', 'administrators');
return Permission::checkMember($member, $codes);
}
/**
* Retrieve a human readable description of a response code
*
* @return string
*/
public function getHTTPCodeDescription() {
$code = $this->HTTPCode;
if(empty($code)) {
// Assume that $code = 0 means there was no response
$description = _t(__CLASS__.'.NOTAVAILABLE', 'Server Not Available');
} elseif(
($descriptions = Config::inst()->get('SS_HTTPResponse', 'status_codes'))
&& isset($descriptions[$code])
) {
$description = $descriptions[$code];
} else {
$description = _t(__CLASS__.'.UNKNOWNRESPONSE', 'Unknown Response Code');
}
return sprintf("%d (%s)", $code, $description);
}
}

View File

@ -30,7 +30,7 @@ class BrokenExternalLinksReport extends SS_Report {
);
}
),
'HTTPCode' => 'HTTP Error Code',
'HTTPCodeDescription' => 'HTTP Error Code',
"Title" => array(
"title" => 'Page link is on',
'formatting' => function($value, $item) {

View File

@ -118,6 +118,16 @@ class ExternalLinksTest extends SapphireTest {
);
$actual = $links->map('Link', 'HTTPCode')->toArray();
$this->assertEquals($expected, $actual);
// Check response descriptions are correct
i18n::set_locale('en_NZ');
$expected = array(
'http://www.broken.com' => '403 (Forbidden)',
'http://www.broken.com/url/thing' => '404 (Not Found)',
'http://www.nodomain.com' => '0 (Server Not Available)'
);
$actual = $links->map('Link', 'HTTPCodeDescription')->toArray();
$this->assertEquals($expected, $actual);
}
/**