minifyhtml.test in Minify Source HTML 7
File
tests/minifyhtml.test
View source
<?php
class MinifyHtmlUnitTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Minify HTML unit tests',
'description' => 'Test all code in the module.',
'group' => 'Minify HTML',
);
}
public function setUp() {
drupal_load('module', 'minifyhtml');
parent::setUp();
}
public function testMinifyHtmlTextareaReplacement() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= " <textarea cols=\"55\" rows=\"31\">\n";
$input .= "Content in here will not matter.\n";
$input .= "Even multiline content.\n";
$input .= "</textarea>\n";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body><textarea cols=\"55\" rows=\"31\">\n";
$expected_output .= "Content in here will not matter.\n";
$expected_output .= "Even multiline content.\n";
$expected_output .= "</textarea></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
public function testMinifyHtmlPreReplacement() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= " <pre>\n";
$input .= " Indented content.\n";
$input .= " Weirdly Indented content.\n";
$input .= "Non-indented content.\n";
$input .= "</pre>\n";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body><pre>\n";
$expected_output .= " Indented content.\n";
$expected_output .= " Weirdly Indented content.\n";
$expected_output .= "Non-indented content.\n";
$expected_output .= "</pre></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
public function testMinifyHtmlIframeReplacement() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= " <iframe src=\"\" width=\"100\" height=\"100\" ></iframe>\n";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body><iframe src=\"\" width=\"100\" height=\"100\" ></iframe></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
public function testMinifyHtmlScriptReplacement() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= " <script>\n";
$input .= "alert('test');\n";
$input .= " </script>\n";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body><script>\n";
$expected_output .= "alert('test');\n";
$expected_output .= "</script></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
public function testMinifyHtmlStyleReplacement() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= " <style>\n";
$input .= "body { color: #fff; }\n";
$input .= " </style>\n";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body><style>\n";
$expected_output .= "body { color: #fff; }\n";
$expected_output .= "</style></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
public function testMinifyHtmlStripComments() {
$input = "<html>\n";
$input .= " <head>\n";
$input .= " <title>Test HTML</title>\n";
$input .= " </head>\n";
$input .= " <body>\n";
$input .= "<!-- The body goes here //-->";
$input .= " </body>\n";
$input .= "</html>\n";
$expected_output = "<html><head><title>Test HTML</title></head><body></body></html>";
$actual_output = $input;
minifyhtml_minify($actual_output);
$this
->assertEqual($expected_output, $actual_output, 'Minified source matches expected output.');
}
}