GoogleCSEConfigTest.php in Google Custom Search Engine 8.3
File
tests/src/Functional/GoogleCSEConfigTest.php
View source
<?php
namespace Drupal\Tests\google_cse\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Url;
class GoogleCSEConfigTest extends BrowserTestBase {
public static $modules = [
'google_cse',
'search',
];
protected $defaultTheme = 'stable';
protected $testUser;
protected $testUnauthorizedUser;
protected function initializeTestUser() {
$this->testUser = $this
->drupalCreateUser([
'search Google CSE',
'administer search',
]);
$this->testUnauthorizedUser = $this
->drupalCreateUser();
}
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',
]);
$this
->drupalGet($settings_form_path);
$session
->statusCodeEquals(200);
$fields = [
'edit-path',
'edit-cx',
'edit-results-display-here',
'edit-custom-results-display-overlay',
];
foreach ($fields as $field) {
$session
->fieldExists($field);
}
$edit = [
'edit-id' => 'test_search',
'edit-path' => 'test-search',
'edit-cx' => '0000',
'edit-results-display-here' => 'here',
'edit-custom-results-display-overlay' => 'overlay',
];
$this
->drupalPostForm(NULL, $edit, 'edit-submit');
$session
->statusCodeEquals(200);
$this
->drupalLogout();
$this
->drupalLogin($this->testUnauthorizedUser);
$this
->drupalGet($settings_form_path);
$session
->statusCodeEquals(403);
$this
->drupalLogout();
$this
->drupalGet($settings_form_path);
$session
->statusCodeEquals(403);
$config = $this
->config('search.page.test_search');
$this
->assertEquals('0000', $config
->get('configuration')['cx']);
$this
->assertEquals('overlay', $config
->get('configuration')['custom_results_display']);
$this
->assertEquals('here', $config
->get('configuration')['results_display']);
}
}