public function testLinks() { // Run link checker $task = CheckExternalLinksTask::create(); $task->setSilent(true); // Be quiet during the test! $task->runLinksCheck(); // Get all links checked $status = BrokenExternalPageTrackStatus::get_latest(); $this->assertEquals('Completed', $status->Status); $this->assertEquals(5, $status->TotalPages); $this->assertEquals(5, $status->CompletedPages); // Check all pages have had the correct HTML adjusted for ($i = 1; $i <= 5; $i++) { $page = $this->objFromFixture('ExternalLinksTest_Page', 'page' . $i); $this->assertNotEmpty($page->Content); $this->assertEquals($page->ExpectedContent, $page->Content, "Assert that the content of page{$i} has been updated"); } // Check that the correct report of broken links is generated $links = $status->BrokenLinks()->sort('Link'); $this->assertEquals(4, $links->count()); $this->assertEquals(array('http://www.broken.com', 'http://www.broken.com/url/thing', 'http://www.broken.com/url/thing', 'http://www.nodomain.com'), array_values($links->map('ID', 'Link')->toArray())); // Check response codes are correct $expected = array('http://www.broken.com' => 403, 'http://www.broken.com/url/thing' => 404, 'http://www.nodomain.com' => 0); $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); }
public function sourceRecords() { $track = BrokenExternalPageTrackStatus::get_latest(); if ($track) { return $track->BrokenLinks(); } return new ArrayList(); }
public function start() { // return if the a job is already running $status = BrokenExternalPageTrackStatus::get_latest(); if ($status && $status->Status == 'Running') { return; } // Create a new job if (class_exists('QueuedJobService')) { // Force the creation of a new run BrokenExternalPageTrackStatus::create_status(); $checkLinks = new CheckExternalLinksJob(); singleton('QueuedJobService')->queueJob($checkLinks); } else { //TODO this hangs as it waits for the connection to be released // should return back and continue processing // http://us3.php.net/manual/en/features.connection-handling.php $task = CheckExternalLinksTask::create(); $task->runLinksCheck(); } }
private function updateJobInfo($message) { $track = BrokenExternalPageTrackStatus::get_latest(); if ($track) { $track->JobInfo = $message; $track->write(); } }