Same name in other branches
  1. 8.x-1.x tests/src/Functional/EntityCloneActionTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneActionTest::testActionEntityClone()

Test action entity clone.

Fichier

tests/src/Functional/EntityCloneActionTest.php, line 62

Classe

EntityCloneActionTest
Create an action and test a clone.

Namespace

Drupal\Tests\entity_clone\Functional

Code

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->drupalGet("admin/config/system/actions/add/{$action_key}");
    $this->submitForm($edit, $this->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->drupalGet('entity_clone/action/' . $action->id());
    $this->submitForm($edit, $this->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.');
}