PluginConfigFormTestBase.php in Purge 8.3
File
modules/purge_ui/tests/src/Functional/Form/Config/PluginConfigFormTestBase.php
View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form\Config;
use Drupal\Tests\purge_ui\Functional\Form\AjaxFormTestBase;
abstract class PluginConfigFormTestBase extends AjaxFormTestBase {
protected $dialogRouteTest = FALSE;
protected $instanceId = 'id0';
protected $pluginId = NULL;
protected $formArgs = [
0 => [
'id' => NULL,
'dialog' => FALSE,
],
];
protected $routeParameters = [
'id' => NULL,
];
protected $routeParametersInvalid = [
'id' => 'doesnotexist',
];
public function setUp($switch_to_memory_queue = TRUE) : void {
parent::setUp($switch_to_memory_queue);
$this->routeParameters['id'] = $this->pluginId;
$this->formArgs[0]['id'] = $this->pluginId;
$this
->initializePlugin();
}
protected function initializePlugin() : void {
throw new \Exception("Derivatives need to implement ::initializePlugin().");
}
protected function shouldReturnAjaxProperties() : bool {
return $this->dialogRouteTest;
}
protected function assertTestProperties() : void {
parent::assertTestProperties();
$this
->assertNotNull($this->pluginId, '$pluginId not set');
}
public function testSaveConfigurationPresence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertActionExists('edit-submit', 'Save configuration');
}
public function testSaveConfigurationSubmit() : void {
throw new \LogicException("Implementation of testSaveConfigurationSubmit mandatory!");
}
public function testCancelPresenceOrAbsence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
if ($this->dialogRouteTest) {
$this
->assertActionExists('edit-cancel', 'Cancel');
}
else {
$this
->assertActionNotExists('edit-cancel', 'Cancel');
}
}
public function testCancelSubmit() : void {
$this
->drupalLogin($this->adminUser);
if ($this->dialogRouteTest) {
$ajax = $this
->postAjaxForm([], 'Cancel');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
else {
$this
->assertFalse(FALSE, "Don't mark this test as risky!");
}
}
}