PHP Classes

File: test/test.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP Markdown Parser   test/test.php   Download  
File: test/test.php
Role: Unit test script
Content type: text/plain
Description: Main test script
Class: PHP Markdown Parser
Parse Markdown documents and generate HTML tags
Author: By
Last change: Added support to parse lists with code.
Date: 2 years ago
Size: 11,462 bytes
 

Contents

Class file image Download
<?php /* * test.php * * @(#) test.php,v 1.14 2020/07/26 15:43:03 mlemos Exp * */ $__test_sets = array( 'own'=>array( 'images', 'sample', 'headers', 'lists', 'links', 'strong', 'emphasis', 'code', 'image_links', 'lists_with_code', ), 'original'=>array( 'Amps and angle encoding', 'Auto links', 'Backslash escapes', 'Blockquotes with code blocks', 'Hard-wrapped paragraphs with list-like lines', 'Horizontal rules', 'Inline HTML (Advanced)', 'Inline HTML comments', 'Inline HTML (Simple)', 'Links, inline style', 'Links, reference style', 'Literal quotes in titles', 'Markdown Documentation - Basics', 'Markdown Documentation - Syntax', 'Nested blockquotes', 'Ordered and unordered lists', 'Strong and em together', 'Tabs', 'Tidyness', ) ); $__tests=array( 'images'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/images.txt', 'expectedfile'=>'expect/images.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/images.md' ) ) ), 'sample'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/sample.txt', 'expectedfile'=>'expect/sample.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/sample.md' ) ) ), 'headers'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/headers.txt', 'expectedfile'=>'expect/headers.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/headers.md' ) ) ), 'lists'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/lists.txt', 'expectedfile'=>'expect/lists.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/lists.md' ) ) ), 'links'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/links.txt', 'expectedfile'=>'expect/links.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/links.md' ) ) ), 'strong'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/strong.txt', 'expectedfile'=>'expect/strong.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/strong.md' ) ) ), 'emphasis'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/emphasis.txt', 'expectedfile'=>'expect/emphasis.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/emphasis.md' ) ) ), 'code'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/code.txt', 'expectedfile'=>'expect/code.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/code.md' ) ) ), 'image_links'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/image_links.txt', 'expectedfile'=>'expect/image_links.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/image_links.md' ) ) ), 'lists_with_code'=>array( 'script'=>'../test_markdown_parser.php', 'generatedfile'=>'generated/lists_with_code.txt', 'expectedfile'=>'expect/lists_with_code.txt', 'options'=>array( 'parameters'=>array( 'File'=>'sample/lists_with_code.md' ) ) ), 'Amps and angle encoding'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Amps-and-angle-encoding.html', 'expectedfile'=>'expect/Amps-and-angle-encoding.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Amps-and-angle-encoding.text' ) ) ), 'Auto links'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Auto-links.html', 'expectedfile'=>'expect/Auto-links.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Auto-links.text' ) ) ), 'Backslash escapes'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Backslash-escapes.html', 'expectedfile'=>'expect/Backslash-escapes.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Backslash-escapes.text' ) ) ), 'Blockquotes with code blocks'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Blockquotes-with-code-blocks.html', 'expectedfile'=>'expect/Blockquotes-with-code-blocks.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Blockquotes-with-code-blocks.text' ) ) ), 'Hard-wrapped paragraphs with list-like lines'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Hard-wrapped-paragraphs-with-list-like-lines.html', 'expectedfile'=>'expect/Hard-wrapped-paragraphs-with-list-like-lines.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Hard-wrapped-paragraphs-with-list-like-lines.text' ) ) ), 'Horizontal rules'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Horizontal-rules.html', 'expectedfile'=>'expect/Horizontal-rules.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Horizontal-rules.text' ) ) ), 'Inline HTML (Advanced)'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Inline-HTML-Advanced.html', 'expectedfile'=>'expect/Inline-HTML-Advanced.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Inline-HTML-Advanced.text' ) ) ), 'Inline HTML comments'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Inline-HTML-comments.html', 'expectedfile'=>'expect/Inline-HTML-comments.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Inline-HTML-comments.text' ) ) ), 'Inline HTML (Simple)'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Inline-HTML-Simple.html', 'expectedfile'=>'expect/Inline-HTML-Simple.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Inline-HTML-Simple.text' ) ) ), 'Links, inline style'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Links-inline-style.html', 'expectedfile'=>'expect/Links-inline-style.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Links-inline-style.text' ) ) ), 'Links, reference style'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Links-reference-style.html', 'expectedfile'=>'expect/Links-reference-style.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Links-reference-style.text' ) ) ), 'Literal quotes in titles'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Literal-quotes-in-titles.html', 'expectedfile'=>'expect/Literal-quotes-in-titles.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Literal-quotes-in-titles.text' ) ) ), 'Markdown Documentation - Basics'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Markdown-Documentation-Basics.html', 'expectedfile'=>'expect/Markdown-Documentation-Basics.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Markdown-Documentation-Basics.text' ) ) ), 'Markdown Documentation - Syntax'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Markdown-Documentation-Syntax.html', 'expectedfile'=>'expect/Markdown-Documentation-Syntax.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Markdown-Documentation-Syntax.text' ) ) ), 'Nested blockquotes'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Nested-blockquotes.html', 'expectedfile'=>'expect/Nested-blockquotes.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Nested-blockquotes.text' ) ) ), 'Ordered and unordered lists'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Ordered-and-unordered-lists.html', 'expectedfile'=>'expect/Ordered-and-unordered-lists.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Ordered-and-unordered-lists.text' ) ) ), 'Strong and em together'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Strong-and-em-together.html', 'expectedfile'=>'expect/Strong-and-em-together.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Strong-and-em-together.text' ) ) ), 'Tabs'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Tabs.html', 'expectedfile'=>'expect/Tabs.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Tabs.text' ) ) ), 'Tidyness'=>array( 'script'=>'../markdown_to_html.php', 'generatedfile'=>'generated/Tidyness.html', 'expectedfile'=>'expect/Tidyness.html', 'options'=>array( 'parameters'=>array( 'File'=>'sample/Tidyness.text' ) ) ), ); define('__TEST',1); if(IsSet($_SERVER['argv']) && GetType($_SERVER['argv']) == 'array' && Count($_SERVER['argv']) > 1) { $__few = array(); for($__a = 1; $__a < count($_SERVER['argv']); ++$__a) { $__name = $_SERVER['argv'][$__a]; if(!IsSet($__tests[$__name])) { if(!IsSet($__test_sets[$__name])) die($__name." is not a valid test name.\n"); foreach($__test_sets[$__name] as $__set_name) { if(!IsSet($__tests[$__set_name])) die($__set_name." is not a valid test name from the set ".$__name.".\n"); $__few[$__set_name] = $__tests[$__set_name]; } } else $__few[$__name] = $__tests[$__name]; } $__tests = $__few; } for($__different=$__test=$__checked=0, Reset($__tests); $__test<count($__tests); Next($__tests), $__test++) { $__name=Key($__tests); $__script=$__tests[$__name]['script']; if(!file_exists($__script)) { echo "\n".'Test script '.$__script.' does not exist.'."\n".str_repeat('_',80)."\n"; continue; } echo 'Test "'.$__name.'": ... '; flush(); if(IsSet($__tests[$__name]['options'])) $__test_options=$__tests[$__name]['options']; else $__test_options=array(); ob_start(); require($__script); $output=ob_get_contents(); ob_end_clean(); $generated=$__tests[$__name]['generatedfile']; if(!($file = fopen($generated, 'wb'))) die('Could not create the generated output file '.$generated."\n"); if(!fputs($file, $output) || !fclose($file)) die('Could not save the generated output to the file '.$generated."\n"); $expected=$__tests[$__name]['expectedfile']; if(!file_exists($expected)) { echo "\n".'Expected output file '.$expected.' does not exist.'."\n".str_repeat('_',80)."\n"; continue; } $diff=array(); exec('diff "'.$expected.'" "'.$generated.'"', $diff); if(count($diff)) { echo "FAILED\n".'Output of script '.$__script.' is different from the expected file '.$expected." .\n".str_repeat('_',80)."\n"; for($line=0; $line<count($diff); $line++) echo $diff[$line]."\n"; echo str_repeat('_',80)."\n"; flush(); $__different++; } else echo "OK\n"; $__checked++; } echo $__checked.' test '.($__checked==1 ? 'was' : 'were').' performed, '.($__checked!=$__test ? (($__test-$__checked==1) ? ' 1 test was skipped, ' : ($__test-$__checked).' tests were skipped, ') : '').($__different ? $__different.' failed' : 'none has failed').'.'."\n"; ?>