Same name in other branches
  1. 8.x-1.x tests/src/Functional/EntityCloneCommentTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneCommentTest

Create a comment and test a clone.

@group entity_clone

Hierarchy

  • class \Drupal\Tests\entity_clone\Functional\EntityCloneCommentTest extends \Drupal\Tests\comment\Functional\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait, \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of EntityCloneCommentTest

File

tests/src/Functional/EntityCloneCommentTest.php, line 15

Namespace

Drupal\Tests\entity_clone\Functional
View source
class EntityCloneCommentTest extends CommentTestBase {
    use CommentTestTrait;
    use StringTranslationTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'entity_clone',
        'block',
        'comment',
        'node',
        'history',
        'field_ui',
        'datetime',
    ];
    
    /**
     * Theme to enable by default.
     *
     * @var string
     */
    protected $defaultTheme = 'claro';
    
    /**
     * Permissions to grant admin user.
     *
     * @var array
     */
    protected $permissions = [
        'administer content types',
        'administer comments',
        'administer comment types',
        'administer comment fields',
        'administer comment display',
        'skip comment approval',
        'post comments',
        'access comments',
        'access user profiles',
        'access content',
        'clone comment entity',
    ];
    
    /**
     * Sets the test up.
     */
    protected function setUp() : void {
        parent::setUp();
        $this->adminUser = $this->drupalCreateUser($this->permissions);
        $this->drupalLogin($this->adminUser);
    }
    
    /**
     * Test comment entity clone.
     */
    public function testCommentEntityClone() {
        $subject = 'Test comment for clone';
        $body = $this->randomMachineName();
        $comment = $this->postComment($this->node, $body, $subject, TRUE);
        $this->drupalGet('entity_clone/comment/' . $comment->id());
        $this->submitForm([], $this->t('Clone'));
        $comments = \Drupal::entityTypeManager()->getStorage('comment')
            ->loadByProperties([
            'subject' => $subject . ' - Cloned',
            'comment_body' => $body,
        ]);
        $comments = reset($comments);
        $this->assertInstanceOf(Comment::class, $comments, 'Test comment cloned found in database.');
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityCloneCommentTest::$defaultTheme protected property Theme to enable by default.
EntityCloneCommentTest::$modules protected static property Modules to enable.
EntityCloneCommentTest::$permissions protected property Permissions to grant admin user.
EntityCloneCommentTest::setUp protected function Sets the test up.
EntityCloneCommentTest::testCommentEntityClone public function Test comment entity clone.