You are here

public function TypogrifyClassTest::testWidont in Typogrify 8

Widont test.

File

tests/src/Unit/TypogrifyClassTest.php, line 59

Class

TypogrifyClassTest
Testing all methods on the Typogrify class and their interaction.

Namespace

Drupal\Tests\typogrify\Unit

Code

public function testWidont() {
  $before = 'A very simple test';
  $after = 'A very simple test';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Basic widont. Once sentence, no HTML.');

  // Single word items shouldn't be changed.
  $before = 'Test';
  $after = 'Test';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Single word test #1');
  $before = ' Test';
  $after = ' Test';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Single word test #2');
  $before = '<ul><li>Test</p></li><ul>';
  $after = '<ul><li>Test</p></li><ul>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Single word test #3');
  $before = '<ul><li> Test</p></li><ul>';
  $after = '<ul><li> Test</p></li><ul>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Single word test #4');
  $before = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
  $after = '<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Two paragraphs');
  $before = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
  $after = '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'In a link inside a heading');
  $before = '<h1><a href="#">In a link</a> followed by other text</h1>';
  $after = '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'In a link followed by other text');
  $before = '<h1><a href="#"></a></h1>';
  $after = '<h1><a href="#"></a></h1>';
  $this
    ->assertSame(Typogrify::widont($before), $after, "Empty HTML tags shouldn't cause errors");
  $before = '<div>Divs get no love!</div>';
  $after = '<div>Divs get no love!</div>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Divs get no love');
  $before = '<pre>Neither do PREs</pre>';
  $after = '<pre>Neither do PREs</pre>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'Neither do PREs');
  $before = '<div><p>But divs with paragraphs do!</p></div>';
  $after = '<div><p>But divs with paragraphs&nbsp;do!</p></div>';
  $this
    ->assertSame(Typogrify::widont($before), $after, 'But divs with paragraphs do!');
}