View source
<?php
namespace Drupal\Tests\google_cse\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Url;
use Drupal\search\Entity\SearchPage;
class GoogleCSEDisplayTest extends BrowserTestBase {
public static $modules = [
'block',
'google_cse',
'search',
];
protected $defaultTheme = 'stable';
protected $testUser;
protected function initializeTestUser() {
$this->testUser = $this
->drupalCreateUser([
'administer blocks',
'administer search',
'search content',
'search Google CSE',
]);
}
protected function setUp() {
$this->strictConfigSchema = NULL;
parent::setUp();
$this
->initializeTestUser();
}
public function testConfiguration() {
$this
->drupalLogin($this->testUser);
$session = $this
->assertSession();
$settings_form_path = Url::fromRoute('search.add_type', [
'search_plugin_id' => 'google_cse_search',
]);
$search_page_path = 'test-search';
$search_id = "google_cse_search";
$this
->drupalGet('admin/structure/block');
$this
->getSession()
->getPage()
->findLink('Place block')
->click();
$this
->assertLinkByHref('/admin/structure/block/add/search_form_block/stable', 0, 'Did not find the search block in block candidate list.');
$block = $this
->drupalPlaceBlock('search_form_block');
$this
->drupalGet($settings_form_path);
$edit = [
'edit-id' => $search_id,
'edit-path' => $search_page_path,
'edit-cx' => '0000',
'edit-results-display-here' => 'here',
'edit-custom-results-display-overlay' => 'overlay',
];
$this
->drupalPostForm(NULL, $edit, 'edit-submit');
$search_page_repository = \Drupal::service('search.search_page_repository');
$entity = SearchPage::load($search_id);
$search_page_repository
->setDefaultSearchPage($entity);
$entity_id = $search_page_repository
->getDefaultSearchPage();
$this
->drupalGet('');
$terms = [
'keys' => 'test',
];
$this
->drupalPostForm('', $terms, t('Search'));
$this
->assertEqual($this
->getUrl(), Url::fromRoute('search.view_' . $entity_id, [], [
'query' => [
'keys' => $terms['keys'],
],
'absolute' => TRUE,
])
->toString(), 'Submitted to correct URL.');
$session
->elementExists('css', "div#google-cse-results");
}
}