1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides test methods for topics functionality. |
5
|
|
|
*/ |
6
|
|
|
class TopicsTest extends FetchPageTestCase |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Loads the topics testing fixture. |
11
|
|
|
*/ |
12
|
|
|
public function getDataSet() |
13
|
|
|
{ |
14
|
|
|
return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/topics.xml'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
private function fetch_topics_page($vars) |
18
|
|
|
{ |
19
|
|
|
return $this->base_fetch_page($vars, 'topic', 'index.php', '/topic/index.php'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
private function fetch_topic_page($vars) |
23
|
|
|
{ |
24
|
|
|
return $this->base_fetch_page($vars, 'topic', 'topic.php', '/topic/topic.php'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testTopicsPage() { |
28
|
|
|
$page = $this->fetch_topics_page(array('url' => '/topic/')); |
29
|
|
|
$this->assertContains('Topics', $page); |
30
|
|
|
$this->assertContains('NHS', $page); |
31
|
|
|
$this->assertContains('Welfare', $page); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testTopicsOnFrontPage() { |
35
|
|
|
return $this->base_fetch_page(array('url' => '/'), '/'); |
36
|
|
|
$this->assertContains('NHS', $page); |
|
|
|
|
37
|
|
|
$this->assertNotContains('Welfare', $page); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testTopicPage() { |
41
|
|
|
$page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs')); |
42
|
|
|
$this->assertContains('NHS', $page); |
43
|
|
|
$this->assertNotContains('Welfare', $page); |
44
|
|
|
$this->assertContains('Test Hansard Section', $page); |
45
|
|
|
$this->assertNotContains('foundation hospitals', $page); |
46
|
|
|
$this->assertNotContains('Sign up for email alerts', $page); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testTopicPageWithSearch() { |
50
|
|
|
$page = $this->fetch_topic_page(array('topic' => 'welfare', 'url' => '/topic/welfare')); |
51
|
|
|
$this->assertContains('Welfare', $page); |
52
|
|
|
$this->assertNotContains('NHS', $page); |
53
|
|
|
$this->assertNotContains('Test Hansard Section', $page); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testTopicPageWithMP() { |
57
|
|
|
$page = $this->fetch_topic_page(array('pc' => 'SW1 1AA', 'topic' => 'nhs', 'url' => '/topic/nhs')); |
58
|
|
|
$this->assertContains('NHS', $page); |
59
|
|
|
$this->assertNotContains('Welfare', $page); |
60
|
|
|
$this->assertContains('Test Current-MP', $page); |
61
|
|
|
$this->assertContains('Test Hansard Section', $page); |
62
|
|
|
$this->assertContains('foundation hospitals', $page); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testTopicPageWithMPAndPolicy() { |
66
|
|
|
$page = $this->fetch_topic_page(array('pc' => 'SW1 1AA', 'topic' => 'welfare', 'url' => '/topic/welfare')); |
67
|
|
|
$this->assertContains('Welfare', $page); |
68
|
|
|
$this->assertContains('Test Current-MP', $page); |
69
|
|
|
$this->assertContains('foundation hospitals', $page); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testTopicPageRecentVotes() { |
73
|
|
|
$page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs')); |
74
|
|
|
$this->assertContains('pw-2013-01-01-1-commons">', $page); |
75
|
|
|
$this->assertContains('The majority of MPs voted Agreed', $page); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testTopicPageContent() { |
79
|
|
|
$page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs')); |
80
|
|
|
$this->assertContains('Test Hansard Section', $page); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.