EntityCloneActionTest.php in Entity Clone 8
File
tests/src/Functional/EntityCloneActionTest.php
View source
<?php
namespace Drupal\Tests\entity_clone\Functional;
use Drupal\system\Entity\Action;
use Drupal\Tests\BrowserTestBase;
class EntityCloneActionTest extends BrowserTestBase {
public static $modules = [
'entity_clone',
'action',
];
protected $defaultTheme = 'classy';
protected $permissions = [
'administer actions',
'clone action entity',
];
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($this->adminUser);
}
public function testActionEntityClone() {
foreach (\Drupal::service('plugin.manager.action')
->getDefinitions() as $id => $definition) {
if (is_subclass_of($definition['class'], '\\Drupal\\Core\\Plugin\\PluginFormInterface') && $definition['label'] == 'Send email') {
$action_key = $id;
break;
}
}
$edit = [
'label' => 'Test send email action for clone',
'id' => 'test_send_email_for_clone',
'recipient' => 'test@recipient.com',
'subject' => 'test subject',
'message' => 'test message',
];
$this
->drupalPostForm("admin/config/system/actions/add/{$action_key}", $edit, t('Save'));
$actions = \Drupal::entityTypeManager()
->getStorage('action')
->loadByProperties([
'id' => $edit['id'],
]);
$action = reset($actions);
$edit = [
'label' => 'Test send email action cloned',
'id' => 'test_send_email_cloned',
];
$this
->drupalPostForm('entity_clone/action/' . $action
->id(), $edit, t('Clone'));
$actions = \Drupal::entityTypeManager()
->getStorage('action')
->loadByProperties([
'id' => $edit['id'],
]);
$action = reset($actions);
$this
->assertInstanceOf(Action::class, $action, 'Test action cloned found in database.');
}
}