You are here

public function TypogrifyClassTest::testAmpersandWrapping in Typogrify 8

Tests ampersand-wrapping.

File

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

Class

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

Namespace

Drupal\Tests\typogrify\Unit

Code

public function testAmpersandWrapping() {
  $before = 'John & Robert.';
  $after = 'John <span class="amp">&amp;</span> Robert.';
  $this
    ->assertSame(Typogrify::amp($before), $after, 'Basic ampersand wrapping');
  $before = 'P&T';
  $after = 'P&T';
  $this
    ->assertSame(Typogrify::amp($before), $after, "Don't mess with ampersands in words");
  $before = 'advanced robotics &&nbsp;computing...';
  $after = 'advanced robotics <span class="amp">&amp;</span>&nbsp;computing...';
  $this
    ->assertSame(Typogrify::amp($before), $after, 'One space as HTML entity.');
  $before = 'advanced robotics &amp; computing...';
  $after = 'advanced robotics <span class="amp">&amp;</span> computing...';
  $this
    ->assertSame(Typogrify::amp($before), $after, 'Ampersand as HTML entity.');
  $before = 'advanced robotics&nbsp;&amp;&nbsp;computing...';
  $after = 'advanced robotics&nbsp;<span class="amp">&amp;</span>&nbsp;computing...';
  $this
    ->assertSame(Typogrify::amp($before), $after, 'Both spaces and ampersand as HTML entities.');
  $before = 'P&amp;T had many clients, of which DD&T &amp; Cronhammar, Kronhammer & Hjort were the largest';
  $after = 'P&amp;T had many clients, of which DD&T <span class="amp">&amp;</span> Cronhammar, Kronhammer <span class="amp">&amp;</span> Hjort were the largest';
  $this
    ->assertSame(Typogrify::amp($before), $after, 'Both spaces and ampersand as HTML entities.');
}