This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
PageContentsParsingTest.php
72 lines (61 loc) · 2.11 KB
/
PageContentsParsingTest.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
define('PIECRUST_ROOT_DIR', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
define('PIECRUST_TEST_DATA_DIR', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'test-data' . DIRECTORY_SEPARATOR);
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'util.php';
require_once 'PieCrust.class.php';
class TestPage extends Page
{
public static function create(PieCrust $pieCrust, $uri, $path)
{
$page = new TestPage($pieCrust, null);
$page->uri = $uri;
$page->path = $path;
return $page;
}
public function validateConfig($config)
{
if (!is_array($config))
{
$config = array();
}
return $this->buildValidatedConfig($config);
}
}
class PageContentsParsingTest extends PHPUnit_Framework_TestCase
{
public function parsePageContentsDataProvider()
{
$data = array();
$htmlFiles = new GlobIterator(PIECRUST_TEST_DATA_DIR . '*.html', (GlobIterator::CURRENT_AS_FILEINFO | GlobIterator::SKIP_DOTS));
foreach ($htmlFiles as $htmlFile)
{
$info = pathinfo($htmlFile);
$ymlFile = $info['dirname'] . DIRECTORY_SEPARATOR . $info['filename'] . '.yml';
if (!is_file($ymlFile)) continue;
$data[] = array($htmlFile, $ymlFile);
}
return $data;
}
/**
* @dataProvider parsePageContentsDataProvider
*/
public function testParsePageContents($testFilename, $expectedResultsFilename)
{
// Create the page that will load our test file.
$pc = new PieCrust();
$pc->setConfig(array(
'site' => array('default_format' => 'none')
));
$p = TestPage::create($pc, '/test', $testFilename);
// Get the stuff we are expecting.
$yamlParser = new sfYamlParser();
$expectedResults = $yamlParser->parse(file_get_contents($expectedResultsFilename));
$expectedConfig = $p->validateConfig($expectedResults['config']);
// Assert!
$this->assertEquals($expectedConfig, $p->getConfig());
$expectedContents = $expectedResults['contents'];
$actualContents = $p->getContents();
//die("/".$expectedContents."/".$actualContents."/");
$this->assertEquals($expectedContents, $actualContents);
}
}