Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Fixed unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic_chabant committed Mar 1, 2011
1 parent 0be185e commit d9b2fcb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
14 changes: 12 additions & 2 deletions tests/test-cases/PageContentsParsingTest.php
@@ -1,5 +1,6 @@
<?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';
Expand Down Expand Up @@ -49,14 +50,23 @@ public function parsePageContentsDataProvider()
*/
public function testParsePageContents($testFilename, $expectedResultsFilename)
{
$pc = new PieCrust(array('url_base' => 'host.local'));
// 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());
$this->assertEquals($expectedResults['contents'], $p->getContents());
$expectedContents = $expectedResults['contents'];
$actualContents = $p->getContents();
//die("/".$expectedContents."/".$actualContents."/");
$this->assertEquals($expectedContents, $actualContents);
}
}
26 changes: 13 additions & 13 deletions tests/test-cases/RequestUriParsingTest.php
Expand Up @@ -9,80 +9,80 @@ public function getRequestUriDataProvider()
return array(
// Standard QUERY
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => null),
'/_index',
false
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => ''),
'/_index',
false
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => '/'),
'/_index',
false
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => '/blah'),
'/blah',
false
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => '/some/path'),
'/some/path',
false
),
array(
array('url_base' => 'host.local/test'),
array('host' => 'host.local', 'url_base' => '/test'),
array('QUERY_STRING' => null),
'/_index',
false
),
array(
array('url_base' => 'host.local/test'),
array('host' => 'host.local', 'url_base' => '/test'),
array('QUERY_STRING' => ''),
'/_index',
false
),
array(
array('url_base' => 'host.local/test'),
array('host' => 'host.local', 'url_base' => '/test'),
array('QUERY_STRING' => '/'),
'/_index',
false
),
array(
array('url_base' => 'host.local/test'),
array('host' => 'host.local', 'url_base' => '/test'),
array('QUERY_STRING' => '/blah'),
'/blah',
false
),
array(
array('url_base' => 'host.local/test'),
array('host' => 'host.local', 'url_base' => '/test'),
array('QUERY_STRING' => '/some/path'),
'/some/path',
false
),
// URL rewriting queries
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => null, 'REQUEST_URI' => '/'),
'/_index',
true
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => null, 'REQUEST_URI' => '/blah'),
'/blah',
true
),
array(
array('url_base' => 'host.local'),
array('host' => 'host.local', 'url_base' => '/'),
array('QUERY_STRING' => '/something/else', 'REQUEST_URI' => '/blah'),
'/blah',
true
Expand Down
1 change: 1 addition & 0 deletions tests/test-data/empty-page.html
@@ -0,0 +1 @@
.
3 changes: 2 additions & 1 deletion tests/test-data/empty-page.yml
@@ -1,2 +1,3 @@
config:
contents:
contents: '.'
end: here.
8 changes: 5 additions & 3 deletions tests/test-data/just-content-page.yml
@@ -1,5 +1,7 @@
config:
contents: |
This is a page with stuff in it.
There's not much, but still this is something.
This is a page with stuff in it.
There's not much, but still this is something.
end: here.
2 changes: 1 addition & 1 deletion tests/test-data/simple-header-page.yml
@@ -1 +1 @@
config: title: Some simple pagecontents: | And now we have some content. Not much, still, but whatever, we are just testing stuff, here.
config: title: Some simple pagecontents: | And now we have some content. Not much, still, but whatever, we are just testing stuff, here. end: here.
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest.php
Expand Up @@ -43,7 +43,7 @@
<?php
foreach ($output as $line)
{
echo $line . "\n";
echo htmlentities($line) . "\n";
}
?>
</pre>
Expand Down
2 changes: 1 addition & 1 deletion website/_piecrust/PieCrust.class.php
Expand Up @@ -257,7 +257,6 @@ protected function validateConfig($config)
{
$config['site'] = array();
}

$config['site'] = array_merge(array(
'title' => 'PieCrust Untitled Website',
'root' => ($this->host . $this->urlBase),
Expand Down Expand Up @@ -423,6 +422,7 @@ public function __construct(array $parameters = null)
else
{
$this->urlBase = '/' . trim($parameters['url_base'], '/') . '/';
if ($this->urlBase == '//') $this->urlBase = '/';
}
}

Expand Down

0 comments on commit d9b2fcb

Please sign in to comment.