migrate tests to phpunit

This commit is contained in:
Emanuil 2013-07-21 23:14:30 +03:00
parent 69de4c46d5
commit 85dd9fd965
11 changed files with 55 additions and 425 deletions

8
phpunit.xml.dist Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite>
<file>tests/Test.php</file>
</testsuite>
</testsuites>
</phpunit>

View File

@ -1,7 +0,0 @@
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ tests/index.php?$1 [L]

47
tests/Test.php Normal file
View File

@ -0,0 +1,47 @@
<?php
include 'Parsedown.php';
class Test extends PHPUnit_Framework_TestCase
{
const provider_dir = 'data/';
/**
* @dataProvider provider
*/
public function testAdd($expected, $actual)
{
$markup = Parsedown::instance()->parse('sdf');
$this->assertEquals($expected, $actual);
}
public function provider()
{
$provider = array();
$DirectoryIterator = new DirectoryIterator(__DIR__.'/'.self::provider_dir);
foreach ($DirectoryIterator as $Item)
{
if ($Item->isFile() and $Item->getExtension() === 'md')
{
$basename = $Item->getBasename('.md');
$markdown = file_get_contents(__DIR__.'/'.self::provider_dir.$basename.'.md');
if ( ! $markdown)
continue;
$expected_markup = file_get_contents(__DIR__.'/'.self::provider_dir.$basename.'.html');
$actual_markup = Parsedown::instance()->parse($markdown);
$provider []= array($expected_markup, $actual_markup);
}
}
return $provider;
}
}

View File

@ -1,51 +0,0 @@
.page {
margin: 0 auto;
width: 640px;
}
.header {
background: #555;
color: #fff;
}
.odd {
background: #fff;
}
.even {
background: #eee;
}
div.fail {
background: #f55;
}
div.pass {
background: #595;
}
span.fail {
color: #d55;
}
span.pass {
color: #595;
}
/* ~ */
p {
margin: 10px 0;
}
th {
font-weight: normal;
text-align: left;
}
th, td {
border-bottom: 1px solid #ddd;
padding: 5px 10px;
}

View File

@ -1,12 +0,0 @@
<?php
include '../Parsedown.php';
$page = $_SERVER['QUERY_STRING']
? 'test'
: 'index';
$dir = 'tests/';
include $page.'_controller.php';
include $page.'_view.php';

View File

@ -1,46 +0,0 @@
<?php
$DirectoryIterator = new DirectoryIterator($dir);
$failed_test_count = 0;
foreach ($DirectoryIterator as $Item)
{
if ($Item->isFile() and $Item->getBasename() != '.DS_Store')
{
if ($Item->getExtension() === 'md')
{
$basename = $Item->getBasename('.md');
$markdown = file_get_contents($dir.$basename.'.md');
$expected_markup = file_get_contents($dir.$basename.'.html');
if ( ! $markdown)
continue;
$Parsedown = Parsedown::instance();
$start = microtime(true);
$actual_markup = $Parsedown->parse($markdown);
$time = microtime(true) - $start;
$time = $time * 1000; # ms?
$time = round($time, 2);
$result = $expected_markup === $actual_markup
? 'pass'
: 'fail';
$result === 'fail' and $failed_test_count ++;
$Tests []= array(
'basename' => $basename,
'name' => str_replace('_', ' ', $basename),
'result' => $result,
'time' => $time,
);
}
}
}

View File

@ -1,54 +0,0 @@
<!DOCTYPE html>
<!-- (c) 2009 - 2013 Emanuil Rusev, All rights reserved. -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="index.css" rel="stylesheet" type="text/css" />
<title>Parsedown Test</title>
</head>
<body>
<div style="padding: 50px; width: 500px;">
<h1 style="margin: 0;"><a href="/">Parsedown PHP</a> » Tests</h1>
<br/>
<table>
<tr class="header">
<th style="width: 480px;">Test</th>
<th style="text-align: right; width: 120px">Time</th>
</tr>
<?php foreach ($Tests as $index => $Test): ?>
<tr class="<?= $index % 2 ? 'even' : 'odd' ?>">
<td><a href="/tests/<?= $Test['basename'] ?>"><?= $Test['name'] ?></a> - <span class="<?= $Test['result'] ?>"><?= $Test['result'] ?></span></td>
<td style="text-align: right;"><?= $Test['time'] ?> ms</td>
</tr>
<?php endforeach ?>
</table>
<div class="<?= $failed_test_count ? 'fail' : 'pass' ?>" style="border-top: 1px solid #555; color: #fff; margin-top: 1px; padding:5px 10px;">
<?php if ($failed_test_count): ?>
<?= $failed_test_count ?> tests failed.
<?php else: ?>
All <?= count($Tests) ?> tests passed.
<?php endif ?>
</div>
</div>
</body>
</html>

View File

@ -1,108 +0,0 @@
/*
*
*
*
*/
a {
color: #159;
outline: none;
text-decoration: none;
}
a img {
border: none;
}
abbr {
border-bottom: 1px solid #ddd;
cursor: help;
padding: 2px 3px;
}
body {
background: #ddd;
color: #333;
font-family: Verdana, Sans-serif;
font-size: 14px;
height: 100%;
line-height: 20px;
margin: 0;
padding: 0;
}
blockquote {
background: #eee;
margin: 0 0 10px 0;
padding: 10px 10px 1px 10px;
}
form {
margin: 0;
padding: 0;
}
h1, h2, h3, h4, h5, h6 {
font-family: Georgia, "Times New Roman", Times, serif;
font-weight: normal;
letter-spacing: 1px;
margin: 20px 0;
}
h1 {
line-height: 30px;
}
html {
height: 100%;
margin: 0;
padding: 0;
overflow-y: scroll;
}
img {
outline: none;
}
input {
font-family: Verdana, Sans-serif;
font-size: 14px;
line-height: 20px;
margin: 0;
}
object {
outline: none;
}
p {
margin-top: 0;
margin-bottom: 10px;
}
select {
font-family: Verdana, Sans-serif;
font-size: 14px;
/* Makes for the same height as <input>. */
height: 40px;
margin: 0;
}
table {
border-spacing: 0;
}
textarea {
background: #fff;
font-family: Verdana, Sans-serif;
font-size: 14px;
line-height: 20px;
margin: 0;
padding: 9px;
width: 280px;
}
ul {
list-style-type: square;
}

View File

@ -1,58 +0,0 @@
/*
*
* ...
*
*/
tr.header td {
background: #333;
color: #fff;
padding: 20px;
}
tr.header a {
color: #fff;
text-decoration: underline;
}
tr.body td {
background: #fff;
padding: 20px;
width: 35%;
}
tr.footer td {
background: #fff;
border-top: 1px solid #999;
padding: 10px 20px;
}
/* ~ */
tr.fail td {
background: #f55;
}
tr.pass td {
background: #5d5;
}
/* ~ */
code {
font-family: Source Code Pro, Monaco, monospace;
}
pre {
margin: 0;
white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */
white-space: -pre-wrap; /* Opera */
white-space: -o-pre-wrap; /* Opera */
white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation) http://www.w3.org/TR/css3-text/#white-space */
word-wrap: break-word; /* IE 5.5+ */
}
span.tag {
color: #b19;
}

View File

@ -1,27 +0,0 @@
<?php
$test = $_SERVER['QUERY_STRING'];
preg_match('/^\w+$/', $test) or die('illegal test name');
$md_file = $dir.$test.'.md';
$mu_file = $dir.$test.'.html';
file_exists($md_file) or die("$md_file not found");
file_exists($mu_file) or die("$mu_file not found");
$md = file_get_contents($md_file);
$expected_mu = file_get_contents($mu_file);
$actual_mu = Parsedown::instance()->parse($md);
$result = $expected_mu === $actual_mu
? 'pass'
: 'fail';
$md = htmlentities($md, ENT_NOQUOTES);
$expected_mu = htmlentities($expected_mu, ENT_NOQUOTES);
$actual_mu = htmlentities($actual_mu, ENT_NOQUOTES);
$name = str_replace('_', ' ', $test);
$name = ucwords($name);

View File

@ -1,62 +0,0 @@
<!DOCTYPE html>
<!-- (c) 2009 - 2013 Emanuil Rusev, All rights reserved. -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="test.css" rel="stylesheet" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-2.0.0.min.js" type="text/javascript"></script>
<title><?= $name ?> &laquo; Parsedown Test</title>
</head>
<body onload="prettyPrint();">
<table style="width: 100%; height: 100%;">
<tr class="<?= $result ?>">
<td colspan="3"></td>
</tr>
<tr class="header">
<td colspan="2"><a href="/">Parsedown PHP</a> » <a href=".">Tests</a> » <?= $name ?></td>
<td style="text-align: right;">
<form action="http://parsedown.org<?= $_SERVER['SERVER_NAME'] === 'parsedown.org.local' ? '.local' : '' ?>/explorer/" method="post">
<input type="hidden" name="text" />
<a id="explorer" href="">Open in Explorer</a>
</form>
</td>
</tr>
<tr class="body" style="height: 100%; vertical-align: top;">
<td style="background: #eee; width: 30%;">
<pre id="md" style="word-wrap: break-word;"><?= $md ?></pre>
</td>
<td><pre class="prettyprint"><code><?= $expected_mu ?></code></pre></td>
<td><pre class="prettyprint"><code><?= $actual_mu ?></code></pre></td>
</tr>
<tr class="footer">
<td style="background: #eee;">Markdown</td>
<td>Expected Markup</td>
<td>Actual Markup</td>
</tr>
</table>
<script type="text/javascript">
$('#explorer').click(function(e) {
$('input[name=text]').val($('#md').text());
$('form').submit();
return false;
});
</script>
</body>
</html>