You are here

class ShadowModifierTest in Modifiers Pack 8

@coversDefaultClass \Drupal\modifiers_shadow\Plugin\modifiers\ShadowModifier @group modifiers_pack

Hierarchy

Expanded class hierarchy of ShadowModifierTest

File

modules/modifiers_shadow/tests/src/Unit/ShadowModifierTest.php, line 12

Namespace

Drupal\Tests\modifiers_shadow\Unit
View source
class ShadowModifierTest extends UnitTestCase {

  /**
   * @covers ::modification
   */
  public function testModification() {

    // Shadow without hover.
    $actual_1 = ShadowModifier::modification('.selector', [
      'shadow_offset_x' => '1',
      'shadow_offset_y' => '2',
      'shadow_blur' => '3',
      'shadow_spread' => '4',
      'shadow_color_val' => 'rgba(219,112,147,0.1)',
    ]);
    $expected_css_1 = [
      'all' => [
        '.selector::before' => [
          'content:""',
          'display:block',
          'position:absolute',
          'z-index:-1',
          'top:0',
          'left:0',
          'width:100%',
          'height:100%',
          'box-shadow:1px 2px 3px 4px rgba(219,112,147,0.1)',
          'opacity:1',
        ],
      ],
    ];
    $expected_attributes_1 = [
      'all' => [
        '.selector' => [
          'class' => [
            'modifiers-has-background',
          ],
        ],
      ],
    ];
    $this
      ->assertEquals($expected_css_1, $actual_1
      ->getCss());
    $this
      ->assertEmpty($actual_1
      ->getLibraries());
    $this
      ->assertEmpty($actual_1
      ->getSettings());
    $this
      ->assertEquals($expected_attributes_1, $actual_1
      ->getAttributes());
    $this
      ->assertEmpty($actual_1
      ->getLinks());

    // Shadow on hover.
    $actual_2 = ShadowModifier::modification('.selector', [
      'shadow_h_offset_x' => '1',
      'shadow_h_offset_y' => '2',
      'shadow_h_blur' => '3',
      'shadow_h_spread' => '4',
      'shadow_h_color_val' => 'rgba(219,112,147,0.1)',
      'shadow_h_duration' => '1',
    ]);
    $expected_css_2 = [
      'all' => [
        '.selector' => [
          'position:relative',
          'z-index:0',
        ],
        '.selector::before' => [
          'transition:opacity 1s ease-in-out',
        ],
        '.selector:hover::before' => [
          'opacity:0',
        ],
        '.selector::after' => [
          'content:""',
          'display:block',
          'position:absolute',
          'z-index:-1',
          'top:0',
          'left:0',
          'width:100%',
          'height:100%',
          'box-shadow:1px 2px 3px 4px rgba(219,112,147,0.1)',
          'opacity:0',
          'transition:opacity 1s ease-in-out',
        ],
        '.selector:hover::after' => [
          'opacity:1',
        ],
      ],
    ];
    $expected_attributes_2 = [
      'all' => [
        '.selector' => [
          'class' => [
            'modifiers-has-background',
          ],
        ],
      ],
    ];
    $this
      ->assertEquals($expected_css_2, $actual_2
      ->getCss());
    $this
      ->assertEmpty($actual_2
      ->getLibraries());
    $this
      ->assertEmpty($actual_2
      ->getSettings());
    $this
      ->assertEquals($expected_attributes_2, $actual_2
      ->getAttributes());
    $this
      ->assertEmpty($actual_2
      ->getLinks());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ShadowModifierTest::testModification public function @covers ::modification
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340