diff --git a/tests/AlertsPageTest.php b/tests/AlertsPageTest.php
index 6d62a781a7..91a2b15f24 100644
--- a/tests/AlertsPageTest.php
+++ b/tests/AlertsPageTest.php
@@ -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);
@@ -22,12 +26,18 @@ public function testFetchPage() {
public function testKeywordOnly() {
$page = $this->fetch_page([ 'alertsearch' => 'elephant']);
- $this->assertStringContainsString('Receive alerts when [elephant] is mentioned', $page);
+ $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('fetch_page([ 'alertsearch' => 'speaker:2']);
+ $this->assertStringContainsString('Mrs Test Current-MP', $page);
}
public function testPostCodeOnly() {
$page = $this->fetch_page([ 'alertsearch' => 'SE17 3HE']);
- $this->assertStringContainsString('when Mrs Test Current-MP', $page);
+ $this->assertStringContainsString('Mrs Test Current-MP', $page);
}
public function testPostCodeWithKeyWord() {
@@ -49,4 +59,73 @@ public function testPostcodeAndKeywordWithNoSittingMP() {
$this->assertStringContainsString('You have used a postcode and something else', $page);
$this->assertStringNotContainsString('Did you mean to get alerts for when your MP', $page);
}
+
+ public function testBasicKeyWordAlertsCreation() {
+ $page = $this->fetch_page([ 'step' => 'define']);
+ $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('fetch_page([ 'step' => 'review', 'email' => 'test@example.org', 'words[]' => 'fish']);
+ $this->assertStringContainsString('Review Your Alert', $page);
+ $this->assertStringContainsString('fetch_page([ 'step' => 'confirm', 'email' => 'test@example.org', 'words[]' => 'fish']);
+ $this->assertStringContainsString('We’re nearly done', $page);
+ $this->assertStringContainsString('You should receive an email shortly', $page);
+ }
+
+ public function testMultipleKeyWordAlertsCreation() {
+ $page = $this->fetch_page([ 'step' => 'define']);
+ $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('fetch_page([ 'step' => 'review', 'email' => 'test@example.org', 'words[]' => ['fish', 'salmon']]);
+ $this->assertStringContainsString('Review Your Alert', $page);
+ $this->assertStringContainsString('assertStringContainsString('fetch_page([ 'step' => 'confirm', 'email' => 'test@example.org', 'words[]' => ['fish', 'salmon']]);
+ $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('get_page([ 'step' => 'review', 'words[]' => ['fish', 'salmon']]);
+ $this->assertStringContainsString('Review Your Alert', $page);
+ $this->assertStringContainsString('assertStringContainsString('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('get_page(['step' => 'review', 'words[]' => 'fish', 'search_section' => 'debates']);
+ $this->assertStringContainsString('Review Your Alert', $page);
+ $this->assertStringContainsString('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('get_page(['step' => 'review', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
+ $this->assertStringContainsString('Review Your Alert', $page);
+ $this->assertStringContainsString('assertStringContainsString('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);
+ }
}
diff --git a/tests/FetchPageTestCase.php b/tests/FetchPageTestCase.php
index 352dfbfc47..07b6334544 100644
--- a/tests/FetchPageTestCase.php
+++ b/tests/FetchPageTestCase.php
@@ -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) {
@@ -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) {
diff --git a/tests/_fixtures/alertspage.xml b/tests/_fixtures/alertspage.xml
index e237dec30d..b1c65e678c 100644
--- a/tests/_fixtures/alertspage.xml
+++ b/tests/_fixtures/alertspage.xml
@@ -150,6 +150,14 @@
+
+ 1
+ Test
+ User
+ user@example.org
+ $2y$10$UNelQZqpPpO1jT.f7DLgeOdp.WBT81c5ECvOeTMFeQTBTyq3aCh8q
+ 1
+