Skip to content

Commit

Permalink
add in some more alert page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Oct 31, 2024
1 parent eb8b4f1 commit 4f59800
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
52 changes: 48 additions & 4 deletions tests/AlertsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ private function fetch_page($vars) {
return $this->base_fetch_page($vars, 'alert');
}

private function get_page($vars = []) {
return $this->base_fetch_page_user($vars, '1.fbb689a0c092f5534b929d302db2c8a9', 'alert');
}

public function testFetchPage() {
$page = $this->fetch_page([]);
$this->assertStringContainsString('TheyWorkForYou Email Alerts', $page);
Expand All @@ -23,7 +27,7 @@ public function testFetchPage() {
public function testKeywordOnly() {
$page = $this->fetch_page([ 'alertsearch' => 'elephant']);
$this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value="fire"', $page);
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value="elephant"', $page);
}

public function testSpeakerId() {
Expand Down Expand Up @@ -67,7 +71,7 @@ public function testBasicKeyWordAlertsCreation() {

$page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => 'fish']);
$this->assertStringContainsString('We’re nearly done', $page);
//$this->assertStringContainsString('You will now receive email alerts on any day when [fish] is mentioned in parliament', $page);
$this->assertStringContainsString('You should receive an email shortly', $page);
}

public function testMultipleKeyWordAlertsCreation() {
Expand All @@ -78,10 +82,50 @@ public function testMultipleKeyWordAlertsCreation() {
$page = $this->fetch_page([ 'step' => 'review', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]);
$this->assertStringContainsString('Review Your Alert', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page);

$page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]);
$this->assertStringContainsString('We’re nearly done', $page);
$this->assertStringContainsString('You should receive an email shortly', $page);
}

public function testMultipleKeyWordAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
$this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);

$page = $this->get_page([ 'step' => 'review', 'words[]' => ['fish', 'salmon']]);
$this->assertStringContainsString('Review Your Alert', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page);

$page = $this->get_page([ 'step' => 'confirm', 'words[]' => ['fish', 'salmon']]);
$this->assertStringContainsString('You will now receive email alerts on any day when [fish salmon] is mentioned in parliament', $page);
}

public function testKeyWordAndSectionAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
$this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);

$page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'search_section' => 'debates']);
$this->assertStringContainsString('Review Your Alert', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);

$page = $this->get_page(['step' => 'confirm', 'words[]' => 'fish', 'search_section' => 'debates']);
$this->assertStringContainsString('You will now receive email alerts on any day when [fish] is mentioned in House of Commons debates', $page);
}

public function testKeyWordAndSpeakerAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
$this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);

$page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
$this->assertStringContainsString('Review Your Alert', $page);
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
$this->assertStringContainsString('<input type="hidden" name="representative" value="Mrs Test Current-MP"', $page);

$page = $this->get_page([ 'step' => 'confirm', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
$this->assertStringContainsString('You will now receive email alerts on any day when Mrs Test Current-MP mentions [fish] in parliament', $page);
}
}
20 changes: 18 additions & 2 deletions tests/FetchPageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
abstract class FetchPageTestCase extends TWFY_Database_TestCase {
protected function base_fetch_page($vars, $dir, $page = 'index.php', $req_uri = '') {
foreach ($vars as $k => $v) {
$vars[$k] = $k . '=' . urlencode($v);
if (strpos($k, '[') !== false) {
if (is_array($vars[$k])) {
$vars[$k] = $k . '=' . join("&$k=", $vars[$k]);
} else {
$vars[$k] = $k . '=' . urlencode($v);
}
} else {
$vars[$k] = $k . '=' . urlencode($v);
}
}

if (!$req_uri) {
Expand All @@ -22,7 +30,15 @@ protected function base_fetch_page($vars, $dir, $page = 'index.php', $req_uri =

protected function base_fetch_page_user($vars, $cookie, $dir, $page = 'index.php', $req_uri = '') {
foreach ($vars as $k => $v) {
$vars[$k] = $k . '=' . urlencode($v);
if (strpos($k, '[') !== false) {
if (is_array($vars[$k])) {
$vars[$k] = $k . '=' . join("&$k=", $vars[$k]);
} else {
$vars[$k] = $k . '=' . urlencode($v);
}
} else {
$vars[$k] = $k . '=' . urlencode($v);
}
}

if (!$req_uri) {
Expand Down
8 changes: 8 additions & 0 deletions tests/_fixtures/alertspage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@
<table_data name="titles_ignored">
</table_data>
<table_data name="users">
<row>
<field name="user_id">1</field>
<field name="firstname">Test</field>
<field name="lastname">User</field>
<field name="email">[email protected]</field>
<field name="password">$2y$10$UNelQZqpPpO1jT.f7DLgeOdp.WBT81c5ECvOeTMFeQTBTyq3aCh8q</field>
<field name="confirmed">1</field>
</row>
</table_data>
<table_data name="uservotes">
</table_data>
Expand Down

0 comments on commit 4f59800

Please sign in to comment.