CVS update: /cowiki/misc/development/tests/
[email protected] 7 May 2005 17:10:59 -0000
| Newsgroups | gmane.comp.php.cowiki.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: cmarble
Date: 2005/05/07 10:10:59
Added:
cowiki/misc/development/tests/ParserTest.php
cowiki/misc/development/tests/RunTests.php
cowiki/misc/development/tests/setup.php
Log:
Initial checkin. Requires PEAR::PHPUnit.
Edit setup.php to point to coWiki source.
Run `php -f RunTests.php`.
ParserTest.php now includes reverse parser tests for all but trivial tests.
Work to be done on...
links, uris, variables, line breaks, plugins, headings, lists & tables.
Completed...
emphasis (wiki and html), justification and sub/superscript
tag-sections (pre, code, posting, quote, noop)
File Changes:
Directory: /cowiki/misc/development/tests/
==========================================
File [added]: ParserTest.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/ParserTest.php?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 666
----------------
<?php
//--------------------------------------------------------------------------
// Basic tests for formatting paragraphs
//--------------------------------------------------------------------------
class ParserBasicFormattingTest extends PHPUnit_TestCase {
private $p = nil;
private $r = nil;
//--------------------------------------------------------------
// Setup: Set up an instance of the parser for testing
//--------------------------------------------------------------
function setUp() {
$this->p = CoWikiParser :: getInstance();
$this->r = TestReverseParser :: getInstance();
}
//--------------------------------------------------------------
// Test an empty string
//--------------------------------------------------------------
function testEmptyString() {
$inputString = "";
$outputString = "";
$messageString = "Empty input should produce empty output";
$reformString = "";
$ressageString = "Empty output should produce empty input";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
$this->assertEquals($reformString, $this->r->parse($outputString), $ressageString);
}
//--------------------------------------------------------------
// Test blank lines
//--------------------------------------------------------------
function testBlankLines() {
$inputString = "\n\n\r\n";
$outputString = "";
$messageString = "Blank lines should produce empty output";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
}
//--------------------------------------------------------------
// Test line with no terminator
//--------------------------------------------------------------
function testShortLine() {
$inputString = "Line with no eol";
$outputString = "<p>Line with no eol</p>";
$messageString = "Lines with no <eol> are a paragraph";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
}
//--------------------------------------------------------------
// Test a single plain paragraph
//--------------------------------------------------------------
function testParagraphLine() {
$inputString = "Line with eol\n";
$outputString = "<p>Line with eol</p>";
$messageString = "Lines with <eol> are a paragraph";
$reformString = $inputString;
$ressageString = "Paragraphs are a line with eol";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
$this->assertEquals($reformString, $this->r->parse($outputString), $ressageString);
}
//--------------------------------------------------------------
// Test two paragraphs separated by <eoln>
//--------------------------------------------------------------
function testTwoParagraphs() {
$inputString = "Line with eol\n\nAnd another paragraph\n";
$outputString = "<p>Line with eol</p><p>And another paragraph</p>";
$messageString = "Multiple lines ending in <eol> are paragraphs";
$reformString = $inputString;
$ressageString = "Paragraphs are multiple lines";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
$this->assertEquals($reformString, $this->r->parse($outputString), $ressageString);
}
//--------------------------------------------------------------
// Test paragraphs are recognized with <cr> only eoln
//--------------------------------------------------------------
function testCROnlyLineEndings() {
$inputString = "A\rB\r\rC";
$outputString = "<p>A</p><p>B</p><p>C</p>";
$messageString = "Multiple lines ending in CR";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
}
//--------------------------------------------------------------
// Test paragraphs are recognized with <cr><lf> eoln
//--------------------------------------------------------------
function testCRLFLineEndings() {
$inputString = "A\r\nB\r\nC";
$outputString = "<p>A</p><p>B</p><p>C</p>";
$messageString = "Multiple lines ending in CR-LF";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
}
//--------------------------------------------------------------
// Test paragraphs are recognized with <lf><cr> eoln
//--------------------------------------------------------------
function testLFCRLineEndings() {
$inputString = "A\n\rB\n\rC";
$outputString = "<p>A</p><p>B</p><p>C</p>";
$messageString = "Multiple lines ending in CR-LF";
$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
}
}
//--------------------------------------------------------------------------
// Basic tests for formatting text within paragraphs
//--------------------------------------------------------------------------
class ParserEmphasisFormattingTest extends PHPUnit_TestCase {
var $p = nil;
var $r = nil;
var $testType = "Undefined";
var $formatChar = "?";
var $startTag = "<start>";
var $endTag = "</start>";
//--------------------------------------------------------------
// Standard constructor for unit tests.
//--------------------------------------------------------------
function __construct($name, $type, $format, $start, $end) {
$this->formatChar = $format;
$this->startTag = $start;
$this->endTag = $end;
$this->PHPUnit_TestCase($name);
}
//--------------------------------------------------------------
// Setup: Set up an instance of the parser for testing
//--------------------------------------------------------------
function setUp() {
$this->p = CoWikiParser :: getInstance();
$this->r = TestReverseParser :: getInstance();
}
//--------------------------------------------------------------
// Helper function to generate input and output strings
//--------------------------------------------------------------
function generateWikiEmphasis($emphasis, $startTag, $endTag, $begin, $middle, $ending, & $input, & $output) {
$input = $begin.$emphasis.$middle.$emphasis.$ending;
$output = "<p>".$begin.$startTag.$middle.$endTag.$ending."</p>";
}
//--------------------------------------------------------------
// TODO: Need to check how special characters like punctuation
// affect emphasis. "This *word!* should /emphasize/.
//--------------------------------------------------------------
//--------------------------------------------------------------
// Test emphasis on a single word
//--------------------------------------------------------------
function testEmphasizeWord() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->formatChar.$this->formatChar, $this->startTag, $this->endTag, "start ", "middle", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test emphasis on a phrase
//--------------------------------------------------------------
function testEmphasizePhrase() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->formatChar.$this->formatChar, $this->startTag, $this->endTag, "start ", "middle words", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test emphasize an entire line (no terminator)
//--------------------------------------------------------------
function testEmphasizeLine() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->formatChar.$this->formatChar, $this->startTag, $this->endTag, "", "middle words", "", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test mismatched emphasis
//--------------------------------------------------------------
function testMismatchedEmphasizedPhrase() {
$inputString = "this phrase ".$this->formatChar.$this->formatChar."is mismatched";
$outputString = "<p>this phrase ".$this->formatChar.$this->formatChar."is mismatched</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test "this phrase **is** **mismatched in an intersting way"
//--------------------------------------------------------------
function testMismatchedEmphasizedPhrase2() {
$inputString = "this phrase ".$this->formatChar.$this->formatChar."is".$this->formatChar.$this->formatChar." ".$this->formatChar.$this->formatChar."mismatched in an intersting way";
$outputString = "<p>this phrase ".$this->startTag."is".$this->endTag." ".$this->formatChar.$this->formatChar."mismatched in an intersting way</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//------------------------------------------------------------------
// Test "this phrase ***is*** ****mismatched in an intersting way"
//------------------------------------------------------------------
function testMismatchedEmphasizedPhrase3() {
$inputString = "this phrase ".$this->formatChar.$this->formatChar.$this->formatChar."is".$this->formatChar.$this->formatChar.$this->formatChar." ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar."mismatched in an intersting way";
$outputString = "<p>this phrase ".$this->formatChar.$this->formatChar.$this->formatChar."is".$this->formatChar.$this->formatChar.$this->formatChar." ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar.'mismatched in an intersting way</p>';
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------------
// Test "this phrase ****is**** ****mismatched in an intersting way"
//--------------------------------------------------------------------
function testMismatchedEmphasizedPhrase4() {
$inputString = "this phrase ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar."is".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar." ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar."mismatched in an intersting way";
$outputString = "<p>this phrase ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar."is".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar." ".$this->formatChar.$this->formatChar.$this->formatChar.$this->formatChar."mismatched in an intersting way</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//------------------------------------------------------------------
// Test "A **Emphasize phrase\ncannot continue** across a line."
//------------------------------------------------------------------
function testEmphasizeEndsAtEoln() {
$inputString = "A ".$this->formatChar.$this->formatChar."Emphasize phrase\n\ncannot continue".$this->formatChar.$this->formatChar." across a line.";
$outputString = "<p>A ".$this->formatChar.$this->formatChar."Emphasize phrase</p><p>cannot continue".$this->formatChar.$this->formatChar." across a line.</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
}
//--------------------------------------------------------------------------
// Asterisk: Bold emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserBoldAsteriskFormattingTest extends ParserEmphasisFormattingTest {
function __construct($name) {
ParserEmphasisFormattingTest :: __construct($name, "Bold", "*", '<b origin="wiki">', "</b>");
}
}
//--------------------------------------------------------------------------
// Slash: Italic emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserItalicSlashFormattingTest extends ParserEmphasisFormattingTest {
function __construct($name) {
ParserEmphasisFormattingTest :: __construct($name, "Italics", "/", '<i origin="wiki">', "</i>");
}
}
//--------------------------------------------------------------------------
// Underline: Underscore emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserUnderlineUnderbarFormattingTest extends ParserEmphasisFormattingTest {
function __construct($name) {
ParserEmphasisFormattingTest :: __construct($name, "Underline", "_", '<u origin="wiki">', "</u>");
}
}
//--------------------------------------------------------------------------
// Equals: Fixed font emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserFixedwidthEqualsFormattingTest extends ParserEmphasisFormattingTest {
function __construct($name) {
ParserEmphasisFormattingTest :: __construct($name, "Fixed", "=", '<tt origin="wiki">', "</tt>");
}
}
//--------------------------------------------------------------------------
// Hyphen: Strikeout emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserstrikeoutHyphenFormattingTest extends ParserEmphasisFormattingTest {
function __construct($name) {
ParserEmphasisFormattingTest :: __construct($name, "Fixed", "-", '<strike origin="wiki">', "</strike>");
}
}
//--------------------------------------------------------------------------
// Basic tests for formatting text with <tags> within paragraphs
//--------------------------------------------------------------------------
class ParserTagEmphasisFormattingTest extends PHPUnit_TestCase {
var $p = nil;
var $r = nil;
var $testType = "Undefined";
var $startFormat = "<?>";
var $endFormat = "</?>";
var $startTag = "<start>";
var $endTag = "</start>";
//--------------------------------------------------------------
// Standard constructor for unit tests.
//--------------------------------------------------------------
function __construct($name, $type, $formatStart, $formatEnd, $start, $end) {
$this->startFormat = $formatStart;
$this->endFormat = $formatEnd;
$this->startTag = $start;
$this->endTag = $end;
$this->PHPUnit_TestCase($name);
}
//--------------------------------------------------------------
// Setup: Set up an instance of the parser for testing
//--------------------------------------------------------------
function setUp() {
$this->p = CoWikiParser :: getInstance();
$this->r = TestReverseParser :: getInstance();
}
//--------------------------------------------------------------
// Helper function to generate input and output strings
//--------------------------------------------------------------
function generateWikiEmphasis($emphasisStart, $emphasisEnd, $startTag, $endTag, $begin, $middle, $ending, & $input, & $output) {
$input = $begin.$emphasisStart.$middle.$emphasisEnd.$ending;
$output = "<p>".$begin.$startTag.$middle.$endTag.$ending."</p>";
}
//--------------------------------------------------------------
// TODO: Need to check how special characters like punctuation
// affect emphasis. "This *word!* should /emphasize/.
//--------------------------------------------------------------
//--------------------------------------------------------------
// Test emphasis on a single word
//--------------------------------------------------------------
function testEmphasizeWord() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test emphasis on a phrase
//--------------------------------------------------------------
function testEmphasizePhrase() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle words", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test emphasize an entire line (no terminator)
//--------------------------------------------------------------
function testEmphasizeLine() {
$inputString = "";
$outputString = "";
$this->generateWikiEmphasis($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "", "middle words", "", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test mismatched emphasis
//--------------------------------------------------------------
function testMismatchedEmphasizedPhrase() {
$inputString = "this phrase ".$this->startFormat."is mismatched";
$outputString = "<p>this phrase ".htmlentities($this->startFormat)."is mismatched</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test "this phrase <b>is</b> <b>mismatched in an intersting way"
//--------------------------------------------------------------
function testMismatchedEmphasizedPhrase2() {
$inputString = "this phrase ".$this->startFormat."is".$this->endFormat." ".$this->startFormat."mismatched in an intersting way";
$outputString = "<p>this phrase ".$this->startTag."is".$this->endTag." ".htmlentities($this->startFormat)."mismatched in an intersting way</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
//------------------------------------------------------------------
// Test "A **Emphasize phrase\ncannot continue** across a line."
//------------------------------------------------------------------
function testEmphasizeEndsAtEoln() {
$inputString = "A ".$this->startFormat."Emphasize phrase\n\ncannot continue".$this->endFormat." across a line.";
$outputString = "<p>A ".htmlentities($this->startFormat)."Emphasize phrase</p><p>cannot continue".htmlentities($this->endFormat)." across a line.</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
}
//--------------------------------------------------------------------------
// <b>: Bold emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserBoldTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Bold", "<b>", "</b>", '<b origin="html">', "</b>");
}
}
//--------------------------------------------------------------------------
// <i>: Italic emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserItalicTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Italics", "<i>", "</i>", '<i origin="html">', "</i>");
}
}
//--------------------------------------------------------------------------
// <u>: Underscore emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserUnderlineTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Underline", "<u>", "</u>", '<u origin="html">', "</u>");
}
}
//--------------------------------------------------------------------------
// <tt>: Fixed font emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserFixedwidthTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Fixed", "<tt>", "</tt>", '<tt origin="html">', "</tt>");
}
}
//--------------------------------------------------------------------------
// <s>: Strikeout emphasis for text within paragraphs
//--------------------------------------------------------------------------
class ParserStrikeoutTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Strikeout", "<strike>", "</strike>", '<strike origin="html">', "</strike>");
}
}
//--------------------------------------------------------------------------
// <sub>: Subscript for text within paragraphs
//--------------------------------------------------------------------------
class ParserSubscriptTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Subscript", "<sub>", "</sub>", '<sub origin="html">', "</sub>");
}
}
//--------------------------------------------------------------------------
// <sup>: Superscript for text within paragraphs
//--------------------------------------------------------------------------
class ParserSuperscriptTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Superscript", "<sup>", "</sup>", '<sup origin="html">', "</sup>");
}
}
//--------------------------------------------------------------------------
// <left>: Left justification for text within paragraphs
//--------------------------------------------------------------------------
class ParserLeftJustifyTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Left justify", "<left>", "</left>", '<left origin="html">', "</left>");
}
}
//--------------------------------------------------------------------------
// <center>: Center justification for text within paragraphs
//--------------------------------------------------------------------------
class ParserCenterJustifyTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Center justify", "<center>", "</center>", '<center origin="html">', "</center>");
}
}
//--------------------------------------------------------------------------
// <right>: Right justification for text within paragraphs
//--------------------------------------------------------------------------
class ParserRightJustifyTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Right justify", "<right>", "</right>", '<right origin="html">', "</right>");
}
}
//--------------------------------------------------------------------------
// <bad>: Should handle bad tags OK!
//--------------------------------------------------------------------------
class ParserBadTagFormattingTest extends ParserTagEmphasisFormattingTest {
function __construct($name) {
ParserTagEmphasisFormattingTest :: __construct($name, "Bad Tag", "<bad>", "</bad>", '<bad>', "</bad>");
}
//--------------------------------------------------------------
// Helper function to generate input and output strings
//--------------------------------------------------------------
function generateWikiEmphasis($emphasisStart, $emphasisEnd, $startTag, $endTag, $begin, $middle, $ending, & $input, & $output) {
$input = $begin.$emphasisStart.$middle.$emphasisEnd.$ending;
$output = "<p>".htmlentities($begin.$startTag.$middle.$endTag.$ending)."</p>";
}
//--------------------------------------------------------------
// Test "this phrase <b>is</b> <b>mismatched in an intersting way"
//--------------------------------------------------------------
function testMismatchedEmphasizedPhrase2() {
$inputString = "this phrase ".$this->startFormat."is".$this->endFormat." ".$this->startFormat."mismatched in an intersting way";
$outputString = "<p>this phrase ".htmlentities($this->startTag."is".$this->endTag)." ".htmlentities($this->startFormat)."mismatched in an intersting way</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
}
}
//--------------------------------------------------------------------------
// Basic tests for formatting text with <tags> within paragraphs
//--------------------------------------------------------------------------
class ParserGreedyTagFormattingTest extends PHPUnit_TestCase {
var $p = nil;
var $r = nil;
var $testType = "Undefined";
var $startFormat = "<?>";
var $endFormat = "</?>";
var $startTag = "<start>";
var $endTag = "</start>";
//--------------------------------------------------------------
// Standard constructor for unit tests.
//--------------------------------------------------------------
function __construct($name, $type, $formatStart, $formatEnd, $start, $end) {
$this->startFormat = $formatStart;
$this->endFormat = $formatEnd;
$this->startTag = $start;
$this->endTag = $end;
$this->PHPUnit_TestCase($name);
}
//--------------------------------------------------------------
// Setup: Set up an instance of the parser for testing
//--------------------------------------------------------------
function setUp() {
$this->p = CoWikiParser :: getInstance();
$this->r = TestReverseParser :: getInstance();
}
//--------------------------------------------------------------
// Helper function to generate input and output strings
//--------------------------------------------------------------
function generateWikiGreedy($greedyStart, $greedyEnd, $startTag, $endTag, $begin, $middle, $ending, & $input, & $output) {
$input = $begin.$greedyStart.$middle.$greedyEnd.$ending;
$output = "<p>".$begin.$startTag.$middle.$endTag.$ending."</p>";
}
//--------------------------------------------------------------
// Test greediness on a single word
//--------------------------------------------------------------
function testGreedyWord() {
$inputString = "";
$outputString = "";
$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test greediness on a phrase
//--------------------------------------------------------------
function testGreedyPhrase() {
$inputString = "";
$outputString = "";
$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle words", " end", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test emphasize an entire line (no terminator)
//--------------------------------------------------------------
function testGreedyLine() {
$inputString = "";
$outputString = "";
$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "", "middle words", "", $inputString, $outputString);
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test mismatched greedy tags
//--------------------------------------------------------------
function testMismatchedGreedyPhrase() {
$inputString = "this phrase ".$this->startFormat."is mismatched";
$outputString = "<p>this phrase ".htmlentities($this->startFormat)."is mismatched</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
}
//--------------------------------------------------------------
// Test "this phrase <tag>is</tag> <tag>mismatched in an intersting way"
//--------------------------------------------------------------
function testMismatchedGreedyPhrase2() {
$inputString = "this phrase ".$this->startFormat."is".$this->endFormat." ".$this->startFormat."mismatched in an intersting way";
$outputString = "<p>this phrase ".$this->startTag."is".$this->endTag." ".htmlentities($this->startFormat)."mismatched in an intersting way</p>";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
}
//------------------------------------------------------------------
// Test "A <tag>Greedy phrase \n can continue</tag> across a line."
//------------------------------------------------------------------
function testGreedyOverEoln() {
$inputString = "A ".$this->startFormat."Greedy phrase \ncan continue".$this->endFormat." across a line.";
$outputString = "<p>A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.</p>";
$reformString = "A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.";
$this->assertEquals($outputString, $this->p->parse($inputString));
$this->assertEquals(trim($reformString),trim($this->r->parse($outputString)));
}
}
//--------------------------------------------------------------------------
// <noop>: No-operation tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserNoopTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Noop", "<noop>", "</noop>", '<noop>', "</noop>");
}
}
//--------------------------------------------------------------------------
// <pre>: Pre-formatted tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserPreTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Pre", "<pre>", "</pre>", '<pre>', "</pre>");
}
}
//--------------------------------------------------------------------------
// <code>: Code-formatting tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserCodeTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Code", "<code>", "</code>", '<code>', "</code>");
}
}
//--------------------------------------------------------------------------
// <posting>: Posting-formatted tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserPostingTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Posting", "<posting>", "</posting>", '<posting>', "</posting>");
}
}
//--------------------------------------------------------------------------
// <q>: Quote tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserQTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Q", "<q>", "</q>", '<q>', "</q>");
}
}
//--------------------------------------------------------------------------
// <rem>: Remark tag for text within a paragraph
//--------------------------------------------------------------------------
class ParserRemTagFormattingTest extends ParserGreedyTagFormattingTest {
function __construct($name) {
ParserGreedyTagFormattingTest :: __construct($name, "Rem", "<rem>", "</rem>", '<rem>', "</rem>");
}
}
?>
File [added]: RunTests.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/RunTests.php?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 47
---------------
<?php
//
require_once 'setup.php';
require_once 'ParserTest.php';
$suite = new PHPUnit_TestSuite();
$result = new PHPUnit_TestResult();
$result->addListener(new ConsoleListener);
$suite->addTestSuite(ParserBasicFormattingTest);
$suite->addTestSuite(ParserBoldAsteriskFormattingTest);
$suite->addTestSuite(ParserItalicSlashFormattingTest);
$suite->addTestSuite(ParserUnderlineUnderbarFormattingTest);
$suite->addTestSuite(ParserFixedwidthEqualsFormattingTest);
$suite->addTestSuite(ParserstrikeoutHyphenFormattingTest);
$suite->addTestSuite(ParserBoldTagFormattingTest);
$suite->addTestSuite(ParserItalicTagFormattingTest);
$suite->addTestSuite(ParserUnderlineTagFormattingTest);
$suite->addTestSuite(ParserFixedwidthTagFormattingTest);
$suite->addTestSuite(ParserStrikeoutTagFormattingTest);
$suite->addTestSuite(ParserSubscriptTagFormattingTest);
$suite->addTestSuite(ParserSuperscriptTagFormattingTest);
$suite->addTestSuite(ParserLeftJustifyTagFormattingTest);
$suite->addTestSuite(ParserCenterJustifyTagFormattingTest);
$suite->addTestSuite(ParserRightJustifyTagFormattingTest);
$suite->addTestSuite(ParserBadTagFormattingTest);
$suite->addTestSuite(ParserNoopTagFormattingTest);
$suite->addTestSuite(ParserPreTagFormattingTest);
$suite->addTestSuite(ParserCodeTagFormattingTest);
$suite->addTestSuite(ParserPostingTagFormattingTest);
$suite->addTestSuite(ParserQTagFormattingTest);
$suite->addTestSuite(ParserRemTagFormattingTest);
$suite->run($result);
print $result->toString()."\n\n";
printf("--------------------------------------------------\n");
printf(" %d tests, passed=%d, failed=%d, errors=%d\n", sizeof($result->passedTests()) + $result->failureCount(), sizeof($result->passedTests()), $result->failureCount(), $result->errorCount());
printf("--------------------------------------------------\n");
?>
File [added]: setup.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/setup.php?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 49
---------------
<?php
//--------------------------------------------------------
// This line has to be set because the test code is
// not presently in the coWiki directory structure.
//--------------------------------------------------------
$base_path = "/code/src/cowiki/cowiki/includes/cowiki/";
//--------------------------------------------------------
// The ClassLoader is used to locate and load coWiki class files
//--------------------------------------------------------
include_once $base_path.'class/class.ClassLoader.php';
//--------------------------------------------------------
// This function is called when PHP can't locate a class
//--------------------------------------------------------
function __autoload($sClass) {
ClassLoader::getInstance()->load($sClass);
}
// Some classes need functions defined here. Go ahead and pre-load.
include_once $base_path.'core.function.php';
// Preload the PHPUnit stuff too.
require_once 'PHPUnit.php';
//
// PHPUnit_TestResult only calls the start and end test callbacks.
// *Not* very useful...
//
class ConsoleListener extends PHPUnit_TestListener {
function addError($test, $t) {
// print "MyListener::addError() called.\n";
}
function addFailure($test, $t) {
// print "MyListener::addFailure() called.\n";
}
function endTest($test) {
// print "MyListener::endTest() called.\n";
}
function startTest($test) {
// print "MyListener::startTest() called.\n";
}
}
?>