5 * Unit tests for the basic typogrify functionality.
8 class TypogrifyClassTestCase extends DrupalWebTestCase {
10 * Implements getInfo().
14 'name' => t('typogrify.class basic tests'),
15 'description' => t('Testing all methods on the Typogrify class and their interaction.'),
16 'group' => t('Typogrify'),
24 parent::setUp('typogrify');
28 * Tests ampersand-wrapping.
30 function testAmpersandWrapping() {
31 $before = 'John & Robert.';
32 $after = 'John <span class="amp">&</span> Robert.';
33 $this->assertEqual(Typogrify::amp($before), $after,
34 t('Basic ampersand wrapping'));
38 $this->assertEqual(Typogrify::amp($before), $after,
39 t("Don't mess with ampersands in words"));
41 $before = 'advanced robotics & computing...';
42 $after = 'advanced robotics <span class="amp">&</span> computing...';
43 $this->assertEqual(Typogrify::amp($before), $after,
44 t("One space as HTML entitiy."));
46 $before = 'advanced robotics & computing...';
47 $after = 'advanced robotics <span class="amp">&</span> computing...';
48 $this->assertEqual(Typogrify::amp($before), $after,
49 t("Ampersand as HTML entitiy."));
51 $before = 'advanced robotics & computing...';
52 $after = 'advanced robotics <span class="amp">&</span> computing...';
53 $this->assertEqual(Typogrify::amp($before), $after,
54 t("Both spaces and ampersand as HTML entities."));
56 $before = 'P&T had many clients, of which DD&T & Cronhammar, Kronhammer & Hjort were the largest';
57 $after = 'P&T had many clients, of which DD&T <span class="amp">&</span> Cronhammar, Kronhammer <span class="amp">&</span> Hjort were the largest';
58 $this->assertEqual(Typogrify::amp($before), $after,
59 t("Both spaces and ampersand as HTML entities."));
66 function testWidont() {
67 $before = 'A very simple test';
68 $after = 'A very simple test';
69 $this->assertEqual(Typogrify::widont($before), $after,
70 t('Basic widont. Once sentance, no HTML.'));
72 // Single word items shouldn't be changed.
75 $this->assertEqual(Typogrify::widont($before), $after,
76 t('Single word test #1'));
80 $this->assertEqual(Typogrify::widont($before), $after,
81 t('Single word test #2'));
83 $before = '<ul><li>Test</p></li><ul>';
84 $after = '<ul><li>Test</p></li><ul>';
85 $this->assertEqual(Typogrify::widont($before), $after,
86 t('Single word test #3'));
88 $before = '<ul><li> Test</p></li><ul>';
89 $after = '<ul><li> Test</p></li><ul>';
90 $this->assertEqual(Typogrify::widont($before), $after,
91 t('Single word test #4'));
93 $before = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
94 $after = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
95 $this->assertEqual(Typogrify::widont($before), $after,
98 $before = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
99 $after = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
100 $this->assertEqual(Typogrify::widont($before), $after,
101 t('In a link inside a heading'));
103 $before = '<h1><a href="#">In a link</a> followed by other text</h1>';
104 $after = '<h1><a href="#">In a link</a> followed by other text</h1>';
105 $this->assertEqual(Typogrify::widont($before), $after,
106 t('In a link followed by other text'));
108 $before = '<h1><a href="#"></a></h1>';
109 $after = '<h1><a href="#"></a></h1>';
110 $this->assertEqual(Typogrify::widont($before), $after,
111 t("Empty HTML tags shouldn't cause errors"));
113 $before = '<div>Divs get no love!</div>';
114 $after = '<div>Divs get no love!</div>';
115 $this->assertEqual(Typogrify::widont($before), $after,
116 t('Divs get no love'));
118 $before = '<pre>Neither do PREs</pre>';
119 $after = '<pre>Neither do PREs</pre>';
120 $this->assertEqual(Typogrify::widont($before), $after,
121 t('Neither do PREs'));
123 $before = '<div><p>But divs with paragraphs do!</p></div>';
124 $after = '<div><p>But divs with paragraphs do!</p></div>';
125 $this->assertEqual(Typogrify::widont($before), $after,
126 t('But divs with paragraphs do!'));