typogrify.class.test in Typogrify 7
Same filename and directory in other branches
Unit tests for the basic typogrify functionality.
File
tests/typogrify.class.testView source
<?php
/**
* @file
* Unit tests for the basic typogrify functionality.
*/
class TypogrifyClassTestCase extends DrupalWebTestCase {
/**
* Implements getInfo().
*/
function getInfo() {
return array(
'name' => t('typogrify.class basic tests'),
'description' => t('Testing all methods on the Typogrify class and their interaction.'),
'group' => t('Typogrify'),
);
}
/**
* Implements setUp().
*/
function setUp() {
parent::setUp('typogrify');
module_load_include('class.php', 'typogrify');
}
/**
* Tests ampersand-wrapping.
*/
function testAmpersandWrapping() {
$before = 'John & Robert.';
$after = 'John <span class="amp">&</span> Robert.';
$this
->assertEqual(Typogrify::amp($before), $after, t('Basic ampersand wrapping'));
$before = 'P&T';
$after = 'P&T';
$this
->assertEqual(Typogrify::amp($before), $after, t("Don't mess with ampersands in words"));
$before = 'advanced robotics & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertEqual(Typogrify::amp($before), $after, t("One space as HTML entitiy."));
$before = 'advanced robotics & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertEqual(Typogrify::amp($before), $after, t("Ampersand as HTML entitiy."));
$before = 'advanced robotics & computing...';
$after = 'advanced robotics <span class="amp">&</span> computing...';
$this
->assertEqual(Typogrify::amp($before), $after, t("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
->assertEqual(Typogrify::amp($before), $after, t("Both spaces and ampersand as HTML entities."));
}
/**
* Widont test.
*/
function testWidont() {
$before = 'A very simple test';
$after = 'A very simple test';
$this
->assertEqual(Typogrify::widont($before), $after, t('Basic widont. Once sentance, no HTML.'));
// Single word items shouldn't be changed.
$before = 'Test';
$after = 'Test';
$this
->assertEqual(Typogrify::widont($before), $after, t('Single word test #1'));
$before = ' Test';
$after = ' Test';
$this
->assertEqual(Typogrify::widont($before), $after, t('Single word test #2'));
$before = '<ul><li>Test</p></li><ul>';
$after = '<ul><li>Test</p></li><ul>';
$this
->assertEqual(Typogrify::widont($before), $after, t('Single word test #3'));
$before = '<ul><li> Test</p></li><ul>';
$after = '<ul><li> Test</p></li><ul>';
$this
->assertEqual(Typogrify::widont($before), $after, t('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
->assertEqual(Typogrify::widont($before), $after, t('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
->assertEqual(Typogrify::widont($before), $after, t('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
->assertEqual(Typogrify::widont($before), $after, t('In a link followed by other text'));
$before = '<h1><a href="#"></a></h1>';
$after = '<h1><a href="#"></a></h1>';
$this
->assertEqual(Typogrify::widont($before), $after, t("Empty HTML tags shouldn't cause errors"));
$before = '<div>Divs get no love!</div>';
$after = '<div>Divs get no love!</div>';
$this
->assertEqual(Typogrify::widont($before), $after, t('Divs get no love'));
$before = '<pre>Neither do PREs</pre>';
$after = '<pre>Neither do PREs</pre>';
$this
->assertEqual(Typogrify::widont($before), $after, t('Neither do PREs'));
$before = '<div><p>But divs with paragraphs do!</p></div>';
$after = '<div><p>But divs with paragraphs do!</p></div>';
$this
->assertEqual(Typogrify::widont($before), $after, t('But divs with paragraphs do!'));
}
}
Classes
Name | Description |
---|---|
TypogrifyClassTestCase | @file Unit tests for the basic typogrify functionality. |