1 | <?php |
||
3 | class ExternalLinksTest extends SapphireTest { |
||
|
|||
4 | |||
5 | protected static $fixture_file = 'ExternalLinksTest.yml'; |
||
6 | |||
7 | protected $extraDataObjects = array( |
||
8 | 'ExternalLinksTest_Page' |
||
9 | ); |
||
10 | |||
11 | public function setUpOnce() { |
||
12 | if (class_exists('Phockito')) { |
||
13 | Phockito::include_hamcrest(false); |
||
14 | } |
||
15 | |||
16 | parent::setUpOnce(); |
||
17 | } |
||
18 | |||
19 | public function setUp() { |
||
20 | parent::setUp(); |
||
21 | |||
22 | Injector::nest(); |
||
23 | |||
24 | // Check dependencies |
||
25 | if (!class_exists('Phockito')) { |
||
26 | $this->skipTest = true; |
||
27 | return $this->markTestSkipped("These tests need the Phockito module installed to run"); |
||
28 | } |
||
29 | |||
30 | // Mock link checker |
||
31 | $checker = Phockito::mock('LinkChecker'); |
||
32 | Phockito::when($checker) |
||
33 | ->checkLink('http://www.working.com') |
||
34 | ->return(200); |
||
35 | |||
36 | Phockito::when($checker) |
||
37 | ->checkLink('http://www.broken.com/url/thing') // 404 on working site |
||
38 | ->return(404); |
||
39 | |||
40 | Phockito::when($checker) |
||
41 | ->checkLink('http://www.broken.com') // 403 on working site |
||
42 | ->return(403); |
||
43 | |||
44 | Phockito::when($checker) |
||
45 | ->checkLink('http://www.nodomain.com') // no ping |
||
46 | ->return(0); |
||
47 | |||
48 | Phockito::when($checker) |
||
49 | ->checkLink('/internal/link') |
||
50 | ->return(null); |
||
51 | |||
52 | Phockito::when($checker) |
||
53 | ->checkLink('[sitetree_link,id=9999]') |
||
54 | ->return(null); |
||
55 | |||
56 | Phockito::when($checker) |
||
57 | ->checkLink('home') |
||
58 | ->return(null); |
||
59 | |||
60 | Phockito::when($checker) |
||
61 | ->checkLink('broken-internal') |
||
62 | ->return(null); |
||
63 | |||
64 | Phockito::when($checker) |
||
65 | ->checkLink('[sitetree_link,id=1]') |
||
66 | ->return(null); |
||
67 | |||
68 | Phockito::when($checker) |
||
69 | ->checkLink(Hamcrest_Matchers::anything()) // anything else is 404 |
||
70 | ->return(404); |
||
71 | |||
72 | Injector::inst()->registerService($checker, 'LinkChecker'); |
||
73 | } |
||
74 | |||
75 | public function tearDown() { |
||
79 | |||
80 | public function testLinks() { |
||
81 | // Run link checker |
||
138 | |||
139 | /** |
||
140 | * Test that broken links appears in the reports list |
||
141 | */ |
||
142 | public function testReportExists() { |
||
151 | } |
||
152 | |||
158 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.