3 namespace Drupal\typogrify;
5 class TypogrifyClassTestCase extends DrupalWebTestCase {
8 * Implements getInfo().
10 public function getInfo() {
12 'name' => t('typogrify.class basic tests'),
13 'description' => t('Testing all methods on the Typogrify class and their interaction.'),
14 'group' => t('Typogrify'),
21 public function setUp() {
22 parent::setUp('typogrify');
26 * Tests ampersand-wrapping.
28 public function testAmpersandWrapping() {
29 $before = 'John & Robert.';
30 $after = 'John <span class="amp">&</span> Robert.';
31 $this->assertEqual(Typogrify::amp($before), $after,
32 t('Basic ampersand wrapping'));
36 $this->assertEqual(Typogrify::amp($before), $after,
37 t("Don't mess with ampersands in words"));
39 $before = 'advanced robotics & computing...';
40 $after = 'advanced robotics <span class="amp">&</span> computing...';
41 $this->assertEqual(Typogrify::amp($before), $after,
42 t('One space as HTML entitiy.'));
44 $before = 'advanced robotics & computing...';
45 $after = 'advanced robotics <span class="amp">&</span> computing...';
46 $this->assertEqual(Typogrify::amp($before), $after,
47 t('Ampersand as HTML entitiy.'));
49 $before = 'advanced robotics & computing...';
50 $after = 'advanced robotics <span class="amp">&</span> computing...';
51 $this->assertEqual(Typogrify::amp($before), $after,
52 t('Both spaces and ampersand as HTML entities.'));
54 $before = 'P&T had many clients, of which DD&T & Cronhammar, Kronhammer & Hjort were the largest';
55 $after = 'P&T had many clients, of which DD&T <span class="amp">&</span> Cronhammar, Kronhammer <span class="amp">&</span> Hjort were the largest';
56 $this->assertEqual(Typogrify::amp($before), $after,
57 t('Both spaces and ampersand as HTML entities.'));
64 public function testWidont() {
65 $before = 'A very simple test';
66 $after = 'A very simple test';
67 $this->assertEqual(Typogrify::widont($before), $after,
68 t('Basic widont. Once sentance, no HTML.'));
70 // Single word items shouldn't be changed.
73 $this->assertEqual(Typogrify::widont($before), $after,
74 t('Single word test #1'));
78 $this->assertEqual(Typogrify::widont($before), $after,
79 t('Single word test #2'));
81 $before = '<ul><li>Test</p></li><ul>';
82 $after = '<ul><li>Test</p></li><ul>';
83 $this->assertEqual(Typogrify::widont($before), $after,
84 t('Single word test #3'));
86 $before = '<ul><li> Test</p></li><ul>';
87 $after = '<ul><li> Test</p></li><ul>';
88 $this->assertEqual(Typogrify::widont($before), $after,
89 t('Single word test #4'));
91 $before = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
92 $after = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
93 $this->assertEqual(Typogrify::widont($before), $after,
96 $before = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
97 $after = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
98 $this->assertEqual(Typogrify::widont($before), $after,
99 t('In a link inside a heading'));
101 $before = '<h1><a href="#">In a link</a> followed by other text</h1>';
102 $after = '<h1><a href="#">In a link</a> followed by other text</h1>';
103 $this->assertEqual(Typogrify::widont($before), $after,
104 t('In a link followed by other text'));
106 $before = '<h1><a href="#"></a></h1>';
107 $after = '<h1><a href="#"></a></h1>';
108 $this->assertEqual(Typogrify::widont($before), $after,
109 t("Empty HTML tags shouldn't cause errors"));
111 $before = '<div>Divs get no love!</div>';
112 $after = '<div>Divs get no love!</div>';
113 $this->assertEqual(Typogrify::widont($before), $after,
114 t('Divs get no love'));
116 $before = '<pre>Neither do PREs</pre>';
117 $after = '<pre>Neither do PREs</pre>';
118 $this->assertEqual(Typogrify::widont($before), $after,
119 t('Neither do PREs'));
121 $before = '<div><p>But divs with paragraphs do!</p></div>';
122 $after = '<div><p>But divs with paragraphs do!</p></div>';
123 $this->assertEqual(Typogrify::widont($before), $after,
124 t('But divs with paragraphs do!'));