protected function IntegrationTest::checkFunctionalityRegistered in Search API Saved Searches 8
Checks functionality for registered users.
1 call to IntegrationTest::checkFunctionalityRegistered()
- IntegrationTest::testModule in tests/
src/ Functional/ IntegrationTest.php - Tests overall functionality of the module.
File
- tests/
src/ Functional/ IntegrationTest.php, line 375
Class
- IntegrationTest
- Tests overall functionality of the module.
Namespace
Drupal\Tests\search_api_saved_searches\FunctionalCode
protected function checkFunctionalityRegistered() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->registeredUser);
// Registered users don't have permission yet to use saved searches.
$this
->drupalGet('search-api-test');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Description for the');
$this
->drupalGet('search-api-test-search-view-caching-none');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Description for the');
$this
->drupalGet('search-api-test-sorts');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Description for the');
// Grant the permissions.
$role = Role::load(Role::AUTHENTICATED_ID);
$this
->grantPermissions($role, [
'use default search_api_saved_searches',
'use foobar search_api_saved_searches',
]);
// Now check that there are the expected blocks on all three search pages.
$this
->drupalGet('search-api-test', [
'query' => [
'search_api_fulltext' => 'foo',
],
]);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Default saved searches block');
$assert_session
->pageTextContains('Description for the default type.');
$assert_session
->pageTextNotContains('Foo & Bar saved searches block');
$assert_session
->pageTextNotContains('Description for the foobar type.');
$assert_session
->pageTextNotContains('E-mail');
$edit = [
'label[0][value]' => 'First saved search',
'notify_interval' => '3600',
];
$this
->submitForm($edit, 'Save search');
$assert_session
->pageTextContains('Your saved search was successfully created.');
$assert_session
->pageTextNotContains('You will soon receive an e-mail with a confirmation link to activate it.');
$this
->drupalGet('search-api-test-search-view-caching-none', [
'query' => [
'search_api_fulltext' => 'bar',
],
]);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Foo & Bar saved searches block');
$assert_session
->pageTextContains('Description for the foobar type.');
$assert_session
->pageTextNotContains('Default saved searches block');
$assert_session
->pageTextNotContains('Description for the default type.');
$edit = [
'label[0][value]' => 'Second saved search',
'notify_interval' => '86400',
'mail[0][value]' => 'testuser@example.com',
];
$this
->submitForm($edit, 'Save search');
$assert_session
->pageTextContains('Your saved search was successfully created.');
$assert_session
->pageTextContains('You will soon receive an e-mail with a confirmation link to activate it.');
$this
->drupalGet('search-api-test-sorts');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Description for the');
$captured_emails = \Drupal::state()
->get('system.test_mail_collector');
$mail = array_pop($captured_emails);
$this
->assertEquals('testuser@example.com', $mail['to']);
$regex = '#- (\\w+):\\s+(\\S+)#';
$this
->assertEquals(4, preg_match_all($regex, $mail['body'], $matches, PREG_SET_ORDER));
$mail_urls = [];
foreach ($matches as $match) {
if ($match[1] === 'Activate') {
$this
->assertStringContainsString('token=', $match[2], "{$match[1]} URL for saved search doesn't include a token.");
}
else {
$this
->assertStringNotContainsString('token=', $match[2], "{$match[1]} URL for saved search unnecessarily includes a token.");
}
$mail_urls[$match[1]] = $match[2];
}
// Check URLs for the saved search we got in the mail.
$this
->drupalGet($mail_urls['Activate']);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Your saved search was successfully activated.');
$this
->drupalGet($mail_urls['Activate']);
$assert_session
->statusCodeEquals(404);
$this
->drupalGet($mail_urls['View']);
$assert_session
->statusCodeEquals(200);
$search_url = $this
->buildUrl('search-api-test-search-view-caching-none', [
'query' => [
'search_api_fulltext' => 'bar',
],
]);
$assert_session
->addressEquals($search_url);
$this
->drupalGet($mail_urls['Edit']);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Edit saved search Second saved search');
$assert_session
->pageTextNotContains('Fulltext keywords');
$assert_session
->pageTextContains('Notification interval');
$assert_session
->pageTextContains('E-mail');
$this
->drupalGet($mail_urls['Delete']);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Do you really want to delete this saved search?');
}