EditableDeletableConfigTest.php in Search Autocomplete 2.x
File
src/Tests/Entity/EditableDeletableConfigTest.php
View source
<?php
namespace Drupal\search_autocomplete\Tests\Entity;
use Drupal\search_autocomplete\Entity\AutocompletionConfiguration;
use Drupal\Tests\BrowserTestBase;
class EditableDeletableConfigTest extends BrowserTestBase {
public static $modules = [
'node',
'search_autocomplete',
];
public $adminUser;
public static function getInfo() {
return [
'name' => 'Manage Autocompletion Configuration test.',
'description' => 'Test the access authorization for editable, deletable config.',
'group' => 'Search Autocomplete',
];
}
public function testEditableEntity() {
$config_id = 'search_block';
$config = AutocompletionConfiguration::load($config_id);
$this
->drupalGet('/admin/config/search/search_autocomplete');
$elements = $this
->xpath('//tr[@id="' . $config_id . '"]//li[contains(@class, "edit")]');
$this
->assertTrue(isset($elements[0]), 'Editable config has Edit operation');
$this
->drupalGet('/admin/config/search/search_autocomplete/manage/' . $config_id);
$this
->assertResponse(200, "Editable configuration can be edited from GUI");
$config = AutocompletionConfiguration::load('search_block');
$config
->setEditable(FALSE);
$config
->save();
$this
->drupalGet('/admin/config/search/search_autocomplete');
$elements = $this
->xpath('//tr[@id="' . $config_id . '"]//li[contains(@class, "edit")]');
$this
->assertFalse(isset($elements[0]), 'Editable config has Edit operation');
$this
->drupalGet('/admin/config/search/search_autocomplete/manage/' . $config_id);
$this
->assertResponse(403, "None editable configuration cannot be edited from GUI");
}
public function testDeletableEntity() {
$config_id = 'search_block';
$config = AutocompletionConfiguration::load($config_id);
$this
->drupalGet('/admin/config/search/search_autocomplete');
$elements = $this
->xpath('//tr[@id="' . $config_id . '"]//li[contains(@class, "delete")]');
$this
->assertFalse(isset($elements[0]), 'Deletable config has Delete operation');
$this
->drupalGet('/admin/config/search/search_autocomplete/manage/' . $config_id . '/delete');
$this
->assertResponse(403, "None deletable configuration cannot be deleted from GUI");
$config
->setDeletable(TRUE);
$config
->save();
$this
->drupalGet('/admin/config/search/search_autocomplete');
$elements = $this
->xpath('//tr[@id="' . $config_id . '"]//li[contains(@class, "delete")]');
$this
->assertTrue(isset($elements[0]), 'Deletable config has Delete operation');
$this
->drupalGet('/admin/config/search/search_autocomplete/manage/' . $config_id . '/delete');
$this
->assertResponse(200, "Deletable configuration can be deleted from GUI");
}
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer search autocomplete',
]);
$this
->drupalLogin($this->adminUser);
}
}