You are here

class FontsModifierTest in Modifiers Pack 8

@coversDefaultClass \Drupal\modifiers_fonts\Plugin\modifiers\FontsModifier @group modifiers_pack

Hierarchy

Expanded class hierarchy of FontsModifierTest

File

modules/modifiers_fonts/tests/src/Unit/FontsModifierTest.php, line 12

Namespace

Drupal\Tests\modifiers_fonts\Unit
View source
class FontsModifierTest extends UnitTestCase {

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

    // Fonts stylesheets are empty.
    $actual_1 = FontsModifier::modification('.selector', [
      'fonts_base' => 'normal 300 1.0rem/2.0rem sans-serif',
      'fonts_h1' => 'normal 300 1.6rem/2.0rem sans-serif',
      'fonts_h2' => 'normal 300 1.5rem/2.0rem sans-serif',
      'fonts_h3' => 'normal 300 1.4rem/2.0rem sans-serif',
      'fonts_h4' => 'normal 300 1.3rem/2.0rem sans-serif',
      'fonts_h5' => 'normal 300 1.2rem/2.0rem sans-serif',
      'fonts_h6' => 'normal 300 1.1rem/2.0rem sans-serif',
      'fonts_em' => 'italic 300 1.0rem/2.0rem sans-serif',
      'fonts_strong' => 'normal 600 1.0rem/2.0rem sans-serif',
      'fonts_h1_transform' => 'none',
      'fonts_h2_transform' => 'uppercase',
      'fonts_h3_transform' => 'lowercase',
      'fonts_h4_transform' => 'capitalize',
      'fonts_h5_transform' => 'none',
      'fonts_h6_transform' => 'uppercase',
    ]);
    $expected_css_1 = [
      'all' => [
        '.selector' => [
          'font:normal 300 1.0rem/2.0rem sans-serif',
        ],
        '.selector h1' => [
          'font:normal 300 1.6rem/2.0rem sans-serif',
          'text-transform:none',
        ],
        '.selector h2' => [
          'font:normal 300 1.5rem/2.0rem sans-serif',
          'text-transform:uppercase',
        ],
        '.selector h3' => [
          'font:normal 300 1.4rem/2.0rem sans-serif',
          'text-transform:lowercase',
        ],
        '.selector h4' => [
          'font:normal 300 1.3rem/2.0rem sans-serif',
          'text-transform:capitalize',
        ],
        '.selector h5' => [
          'font:normal 300 1.2rem/2.0rem sans-serif',
          'text-transform:none',
        ],
        '.selector h6' => [
          'font:normal 300 1.1rem/2.0rem sans-serif',
          'text-transform:uppercase',
        ],
        '.selector em' => [
          'font:italic 300 1.0rem/2.0rem sans-serif',
        ],
        '.selector strong' => [
          'font:normal 600 1.0rem/2.0rem sans-serif',
        ],
      ],
    ];
    $this
      ->assertEquals($expected_css_1, $actual_1
      ->getCss());
    $this
      ->assertEmpty($actual_1
      ->getLibraries());
    $this
      ->assertEmpty($actual_1
      ->getSettings());
    $this
      ->assertEmpty($actual_1
      ->getAttributes());
    $this
      ->assertEmpty($actual_1
      ->getLinks());

    // Fonts stylesheets are not empty.
    $actual_2 = FontsModifier::modification('.selector', [
      'fonts_stylesheets' => [
        'https://fonts.googleapis.com/css?family=Font+1+Name',
        'https://fonts.googleapis.com/css?family=Font+2+Name',
      ],
    ]);
    $expected_links_2 = [
      [
        'href' => 'https://fonts.googleapis.com/css?family=Font+1+Name',
        'rel' => 'stylesheet',
      ],
      [
        'href' => 'https://fonts.googleapis.com/css?family=Font+2+Name',
        'rel' => 'stylesheet',
      ],
    ];
    $this
      ->assertEmpty($actual_2
      ->getCss());
    $this
      ->assertEmpty($actual_2
      ->getLibraries());
    $this
      ->assertEmpty($actual_2
      ->getSettings());
    $this
      ->assertEmpty($actual_2
      ->getAttributes());
    $this
      ->assertEquals($expected_links_2, $actual_2
      ->getLinks());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FontsModifierTest::testModification public function @covers ::modification
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.
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