EntityCloneImageStyleTest.php in Entity Clone 8
File
tests/src/Functional/EntityCloneImageStyleTest.php
View source
<?php
namespace Drupal\Tests\entity_clone\Functional;
use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;
class EntityCloneImageStyleTest extends BrowserTestBase {
public static $modules = [
'entity_clone',
'image',
];
protected $defaultTheme = 'classy';
protected $permissions = [
'clone image_style entity',
'administer image styles',
];
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($this->adminUser);
}
public function testImageStyleEntityClone() {
$edit = [
'label' => 'Test image style for clone',
'name' => 'test_image_style_for_clone',
];
$this
->drupalPostForm("admin/config/media/image-styles/add", $edit, 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
->drupalPostForm('entity_clone/image_style/' . $image_style
->id(), $edit, 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
->drupalPostForm('entity_clone/image_style/' . $image_style
->id(), $edit, t('Clone'));
$this
->assertText('New Id cannot be longer than 64 characters');
}
}