Same name in other branches
  1. 2.x tests/src/Functional/EntityCloneImageStyleTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneImageStyleTest

Create an image style and test a clone.

@group entity_clone

Hierarchy

  • class \Drupal\Tests\entity_clone\Functional\EntityCloneImageStyleTest extends \Drupal\Tests\BrowserTestBase uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of EntityCloneImageStyleTest

File

tests/src/Functional/EntityCloneImageStyleTest.php, line 14

Namespace

Drupal\Tests\entity_clone\Functional
View source
class EntityCloneImageStyleTest extends BrowserTestBase {
    use StringTranslationTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'entity_clone',
        'image',
    ];
    
    /**
     * Theme to enable by default.
     *
     * @var string
     */
    protected $defaultTheme = 'claro';
    
    /**
     * Permissions to grant admin user.
     *
     * @var array
     */
    protected $permissions = [
        'clone image_style entity',
        'administer image styles',
    ];
    
    /**
     * An administrative user with permission to configure image styles settings.
     *
     * @var \Drupal\user\UserInterface
     */
    protected $adminUser;
    
    /**
     * Sets the test up.
     */
    protected function setUp() : void {
        parent::setUp();
        $this->adminUser = $this->drupalCreateUser($this->permissions);
        $this->drupalLogin($this->adminUser);
    }
    
    /**
     * Test image style entity clone.
     */
    public function testImageStyleEntityClone() {
        $edit = [
            'label' => 'Test image style for clone',
            'name' => 'test_image_style_for_clone',
        ];
        $this->drupalGet("admin/config/media/image-styles/add");
        $this->submitForm($edit, $this->t('Create new style'));
        $image_styles = \Drupal::entityTypeManager()->getStorage('image_style')
            ->loadByProperties([
            'name' => $edit['name'],
        ]);
        $image_style = reset($image_styles);
        $edit = [
            'id' => 'test_iamge_style_cloned',
            'label' => 'Test image_style cloned',
        ];
        $this->drupalGet('entity_clone/image_style/' . $image_style->id());
        $this->submitForm($edit, $this->t('Clone'));
        $image_styles = \Drupal::entityTypeManager()->getStorage('image_style')
            ->loadByProperties([
            'name' => $edit['id'],
        ]);
        $image_style = reset($image_styles);
        $this->assertInstanceOf(ImageStyle::class, $image_style, 'Test image style cloned found in database.');
        $edit = [
            'id' => 'test_image_style_clone_with_a_really_long_name_that_is_longer_than_the_max_length',
            'label' => 'Test image style clone with a really long name that is longer than the max length',
        ];
        $this->drupalGet('entity_clone/image_style/' . $image_style->id());
        $this->submitForm($edit, $this->t('Clone'));
        $this->assertSession()
            ->pageTextContains('New Id cannot be longer than 64 characters');
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityCloneImageStyleTest::$adminUser protected property An administrative user with permission to configure image styles settings.
EntityCloneImageStyleTest::$defaultTheme protected property Theme to enable by default.
EntityCloneImageStyleTest::$modules protected static property Modules to enable.
EntityCloneImageStyleTest::$permissions protected property Permissions to grant admin user.
EntityCloneImageStyleTest::setUp protected function Sets the test up.
EntityCloneImageStyleTest::testImageStyleEntityClone public function Test image style entity clone.