class TypogrifyClassTest in Typogrify 8
Testing all methods on the Typogrify class and their interaction.
@group typogrify
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\typogrify\Unit\TypogrifyClassTest
Expanded class hierarchy of TypogrifyClassTest
File
- tests/
src/ Unit/ TypogrifyClassTest.php, line 13
Namespace
Drupal\Tests\typogrify\UnitView source
class TypogrifyClassTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public static $modules = [
'typogrify',
];
/**
* Tests ampersand-wrapping.
*/
public function testAmpersandWrapping() {
$before = 'John & Robert.';
$after = 'John <span class="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 & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertSame(Typogrify::amp($before), $after, 'One space as HTML entity.');
$before = 'advanced robotics & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertSame(Typogrify::amp($before), $after, 'Ampersand as HTML entity.');
$before = 'advanced robotics & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertSame(Typogrify::amp($before), $after, 'Both spaces and ampersand as HTML entities.');
$before = 'P&T had many clients, of which DD&T & Cronhammar, Kronhammer & Hjort were the largest';
$after = 'P&T had many clients, of which DD&T <span class="amp">&</span> Cronhammar, Kronhammer <span class="amp">&</span> Hjort were the largest';
$this
->assertSame(Typogrify::amp($before), $after, 'Both spaces and ampersand as HTML entities.');
}
/**
* Widont test.
*/
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 paragraphs</p><p>paragraph 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 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 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 do!</p></div>';
$this
->assertSame(Typogrify::widont($before), $after, 'But divs with paragraphs do!');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
TypogrifyClassTest:: |
public static | property | ||
TypogrifyClassTest:: |
public | function | Tests ampersand-wrapping. | |
TypogrifyClassTest:: |
public | function | Widont test. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |