Skip to content

Commit

Permalink
abstract base tester
Browse files Browse the repository at this point in the history
now PHPUnit runs both test files.
previously PHPUnit only run one.
  • Loading branch information
mauris committed Dec 17, 2012
1 parent 021d514 commit 90c3e2b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 45 deletions.
62 changes: 62 additions & 0 deletions tests/DflyDev/Markdown/BaseParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is a part of the PHP Markdown library.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DflyDev\Markdown;

abstract class BaseParserTest extends \PHPUnit_Framework_TestCase
{

protected $configKeyTabWidth = Parser::CONFIG_TAB_WIDTH;

protected $object;

/**
* Simple test to ensure that parser can be created and most basic of
* Markdown can be transformed.
*/
public function testCreate()
{
$html = $this->object->transform('#Hello World');
$this->assertEquals("<h1>Hello World</h1>\n", $html, 'Simple H1 works');
}

/**
* Test tab width for code blocks
*/
public function testTabWidth()
{
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Default 4 space tab code block works');
$this->configureTabWidth($this->object, 6);
$html = $this->object->transform(' Hello World');
$this->assertEquals("<p>Hello World</p>\n", $html, 'Default 4 space tab code block not triggered when tab width set to 6');
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Setting 6 space tab code block (via method) works');
}

public function testTabWidthConfig()
{
$this->object = new Parser(array($this->configKeyTabWidth => 8));
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Setting 8 space tab code block (via constructor) works');
}

/**
* Configure a Markdown parser for a specific tab width
* @param \dflydev\markdown\MarkdownParser $markdownParser
* @param integer $width
*/
protected function configureTabWidth(Parser $markdownParser, $width)
{
$markdownParser->configureMarkdownParser($this->configKeyTabWidth, $width);
}

}
2 changes: 1 addition & 1 deletion tests/DflyDev/Markdown/ExtraParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace DflyDev\Markdown;

class ExtraParserTest extends ParserTest
class ExtraParserTest extends BaseParserTest
{

protected $configKeyTabWidth = ExtraParser::CONFIG_TAB_WIDTH;
Expand Down
45 changes: 1 addition & 44 deletions tests/DflyDev/Markdown/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,14 @@

namespace DflyDev\Markdown;

class ParserTest extends \PHPUnit_Framework_TestCase
class ParserTest extends BaseParserTest
{

protected $configKeyTabWidth = Parser::CONFIG_TAB_WIDTH;

protected $object;

protected function setUp()
{
$this->object = new Parser();
}

/**
* Simple test to ensure that parser can be created and most basic of
* Markdown can be transformed.
*/
public function testCreate()
{
$html = $this->object->transform('#Hello World');
$this->assertEquals("<h1>Hello World</h1>\n", $html, 'Simple H1 works');
}

/**
* Test tab width for code blocks
*/
public function testTabWidth()
{
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Default 4 space tab code block works');
$this->configureTabWidth($this->object, 6);
$html = $this->object->transform(' Hello World');
$this->assertEquals("<p>Hello World</p>\n", $html, 'Default 4 space tab code block not triggered when tab width set to 6');
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Setting 6 space tab code block (via method) works');
}

public function testTabWidthConfig()
{
$this->object = new Parser(array($this->configKeyTabWidth => 8));
$html = $this->object->transform(' Hello World');
$this->assertEquals("<pre><code>Hello World\n</code></pre>\n", $html, 'Setting 8 space tab code block (via constructor) works');
}

/**
* Configure a Markdown parser for a specific tab width
* @param \dflydev\markdown\MarkdownParser $markdownParser
* @param integer $width
*/
protected function configureTabWidth(Parser $markdownParser, $width)
{
$markdownParser->configureMarkdownParser($this->configKeyTabWidth, $width);
}

}

0 comments on commit 90c3e2b

Please sign in to comment.