View source
<?php
namespace Drupal\Tests\typogrify\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\filter\FilterPluginCollection;
class TypogrifySmartyPantsTest extends KernelTestBase {
public static $modules = [
'typogrify',
'filter',
];
protected $baseSettings = [
'smartypants_enabled' => 1,
'smartypants_hyphens' => 2,
'wrap_ampersand' => 1,
'widont_enabled' => 1,
'wrap_abbr' => 0,
'wrap_caps' => 1,
'wrap_initial_quotes' => 1,
'hyphenate_shy' => 0,
'wrap_numbers' => 0,
'ligatures' => [],
'arrows' => [],
'quotes' => [],
];
public function testTypogrify(array $extra_settings, string $original, string $processed) {
$configuration = [
'settings' => $extra_settings + $this->baseSettings,
];
$manager = $this->container
->get('plugin.manager.filter');
$bag = new FilterPluginCollection($manager, []);
$filter = $bag
->get('typogrify');
$filter
->setConfiguration($configuration);
$this
->assertEquals($processed, $filter
->process($original, 'en'));
}
public function providerTypogrifyExamples() {
$before = <<<HTML
<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>
<p>By J.D. Salinger, Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "Excepteur sint occaecat 'cupidatat' non proident" sunt RFID22 in.... </p>
HTML;
$after = <<<HTML
<h2>“Jayhawks” <span class="amp">&</span> <span class="caps">KU</span> fans act extremely obnoxiously</h2>
<p>By <span class="caps">J.D.</span> Salinger, Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. “Excepteur sint occaecat ‘cupidatat’ non proident” sunt <span class="caps">RFID22</span> in…. </p>
HTML;
$data = [
'original typogrify example' => [
[],
$before,
$after,
],
'test wrap_abbr' => [
[
'wrap_abbr' => 3,
],
"What kind of abbreviations contain two dots like eg.etc. or cd.e.f.?",
'What kind of abbreviations contain two dots like <span class="abbr">eg.<span style="margin-left:0.167em"><span style="display:none"> </span></span>etc.</span> or <span class="abbr">cd.<span style="margin-left:0.167em"><span style="display:none"> </span></span>e.<span style="margin-left:0.167em"><span style="display:none"> </span></span>f.</span>?',
],
'test wrap_numbers' => [
[
'wrap_numbers' => 4,
],
"Mathematicians refer to 1729 as Ramanujan's number. Euler proved that e^(π i) = -1, where π is approximately 3.1415926.",
'Mathematicians refer to <span class="number">1729</span> as Ramanujan’s number. Euler proved that e^(π i) = <span class="number">-1</span>, where π is approximately <span class="number">3.1415926</span>.',
],
];
return $data;
}
}