summaryrefslogtreecommitdiff
path: root/vendor/parsedown-0.9.0/tests/Test.php
blob: e38974ced59e1392518c3df99059abc4dd052a23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

include 'Parsedown.php';

class Test extends PHPUnit_Framework_TestCase
{
	const provider_dir = 'data/';

	/**
	 * @dataProvider provider
	 */
	function test_($markdown, $expected_markup)
	{
		$actual_markup = Parsedown::instance()->parse($markdown);

		$this->assertEquals($expected_markup, $actual_markup);
	}

	function provider()
	{
		$provider = array();

		$path = dirname(__FILE__).'/';

		$DirectoryIterator = new DirectoryIterator($path . '/' . self::provider_dir);

		foreach ($DirectoryIterator as $Item)
		{
			if ($Item->isFile())
			{
				$filename = $Item->getFilename();

				$extension = pathinfo($filename, PATHINFO_EXTENSION);

				if ($extension !== 'md')
					continue;

				$basename = $Item->getBasename('.md');

				$markdown = file_get_contents($path . '/' . self::provider_dir . $basename . '.md');

				if (!$markdown)
					continue;

				$expected_markup = file_get_contents($path . '/' . self::provider_dir . $basename . '.html');
				$expected_markup = str_replace("\r\n", "\n", $expected_markup);
				$expected_markup = str_replace("\r", "\n", $expected_markup);

				$provider [] = array($markdown, $expected_markup);
			}
		}

		return $provider;
	}
}