You are here

protected function ImageEffectsTestBase::addEffectToTestStyle in Image Effects 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::addEffectToTestStyle()
  2. 8.2 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::addEffectToTestStyle()

Add an image effect to the image test style.

Uses the image effect configuration forms, and not API directly, to ensure forms work correctly.

Parameters

array $effect: An array of effect data, with following keys:

  • id: the image effect plugin
  • data: an array of fields for the image effect edit form, with their values.

Return value

string The UUID of the newly added effect.

29 calls to ImageEffectsTestBase::addEffectToTestStyle()
AspectSwitcherTest::testAspectSwitcherEffect in tests/src/Functional/Effect/AspectSwitcherTest.php
AspectSwitcher effect test.
AutoOrientTest::testAutoOrientAllTags in tests/src/Functional/Effect/AutoOrientTest.php
Auto Orientation effect test, all EXIF orientation tags.
AutoOrientTest::testAutoOrientEffect in tests/src/Functional/Effect/AutoOrientTest.php
Auto Orientation effect test.
BackgroundTest::testBackgroundEffect in tests/src/Functional/Effect/BackgroundTest.php
Background effect test.
BrightnessTest::testBrightnessEffect in tests/src/Functional/Effect/BrightnessTest.php
Brightness effect test.

... See full list

File

tests/src/Functional/ImageEffectsTestBase.php, line 109

Class

ImageEffectsTestBase
Base test class for image_effects tests.

Namespace

Drupal\Tests\image_effects\Functional

Code

protected function addEffectToTestStyle(array $effect) {

  // Get image style prior to adding the new effect.
  $image_style_pre = ImageStyle::load($this->testImageStyleName);

  // Add the effect.
  $this
    ->drupalPostForm('admin/config/media/image-styles/manage/' . $this->testImageStyleName, [
    'new' => $effect['id'],
  ], t('Add'));
  if (!empty($effect['data'])) {
    $effect_edit = [];
    foreach ($effect['data'] as $field => $value) {
      $effect_edit['data[' . $field . ']'] = $value;
    }
    $this
      ->drupalPostForm(NULL, $effect_edit, t('Add effect'));
  }

  // Get UUID of newly added effect.
  $this->testImageStyle = ImageStyle::load($this->testImageStyleName);
  foreach ($this->testImageStyle
    ->getEffects() as $uuid => $effect) {
    if (!$image_style_pre
      ->getEffects()
      ->has($uuid)) {
      return $uuid;
    }
  }
  return NULL;
}