You are here

class PlainTextOutputTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php \Drupal\Tests\Component\Render\PlainTextOutputTest

@coversDefaultClass \Drupal\Component\Render\PlainTextOutput @group Utility

Hierarchy

Expanded class hierarchy of PlainTextOutputTest

File

core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php, line 19
Contains \Drupal\Tests\Component\Render\PlainTextOutputTest.

Namespace

Drupal\Tests\Component\Render
View source
class PlainTextOutputTest extends UnitTestCase {

  /**
   * Tests ::renderFromHtml().
   *
   * @param $expected
   *   The expected formatted value.
   * @param $string
   *   A string to be formatted.
   * @param array $args
   *   (optional) An associative array of replacements to make. Defaults to
   *   none.
   *
   * @covers ::renderFromHtml
   * @dataProvider providerRenderFromHtml
   */
  public function testRenderFromHtml($expected, $string, $args = []) {
    $markup = SafeMarkup::format($string, $args);
    $output = PlainTextOutput::renderFromHtml($markup);
    $this
      ->assertSame($expected, $output);
  }

  /**
   * Data provider for ::testRenderFromHtml()
   */
  public function providerRenderFromHtml() {
    $data = [];
    $data['simple-text'] = [
      'Giraffes and wombats',
      'Giraffes and wombats',
    ];
    $data['simple-html'] = [
      'Giraffes and wombats',
      '<a href="/muh">Giraffes</a> and <strong>wombats</strong>',
    ];
    $data['html-with-quote'] = [
      'Giraffes and quote"s',
      '<a href="/muh">Giraffes</a> and <strong>quote"s</strong>',
    ];
    $expected = 'The <em> tag makes your text look like "this".';
    $string = 'The &lt;em&gt; tag makes your text look like <em>"this"</em>.';
    $data['escaped-html-with-quotes'] = [
      $expected,
      $string,
    ];
    $safe_string = $this
      ->prophesize(MarkupInterface::class);
    $safe_string
      ->__toString()
      ->willReturn('<em>"this"</em>');
    $safe_string = $safe_string
      ->reveal();
    $data['escaped-html-with-quotes-and-placeholders'] = [
      $expected,
      'The @tag tag makes your text look like @result.',
      [
        '@tag' => '<em>',
        '@result' => $safe_string,
      ],
    ];
    $safe_string = $this
      ->prophesize(MarkupInterface::class);
    $safe_string
      ->__toString()
      ->willReturn($string);
    $safe_string = $safe_string
      ->reveal();
    $data['safe-string'] = [
      $expected,
      $safe_string,
    ];
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PlainTextOutputTest::providerRenderFromHtml public function Data provider for ::testRenderFromHtml()
PlainTextOutputTest::testRenderFromHtml public function Tests ::renderFromHtml().
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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 259