Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segregate 5.3+ tests, exclude them from phpunit config.
- Loading branch information
Showing
8 changed files
with
215 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Mustache.php. | ||
* | ||
* (c) 2012 Justin Hileman | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* @group lambdas | ||
* @group functional | ||
*/ | ||
class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase { | ||
|
||
private $mustache; | ||
|
||
public function setUp() { | ||
$this->mustache = new Mustache_Mustache; | ||
} | ||
|
||
public function testAnonymousFunctionSectionCallback() { | ||
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}'); | ||
|
||
$foo = new Mustache_Test_FiveThree_Functional_Foo; | ||
$foo->name = 'Mario'; | ||
$foo->wrapper = function($text) { | ||
return sprintf('<div class="anonymous">%s</div>', $text); | ||
}; | ||
|
||
$this->assertEquals(sprintf('<div class="anonymous">%s</div>', $foo->name), $tpl->render($foo)); | ||
} | ||
|
||
public function testSectionCallback() { | ||
$one = $this->mustache->loadTemplate('{{name}}'); | ||
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); | ||
|
||
$foo = new Mustache_Test_FiveThree_Functional_Foo; | ||
$foo->name = 'Luigi'; | ||
|
||
$this->assertEquals($foo->name, $one->render($foo)); | ||
$this->assertEquals(sprintf('<em>%s</em>', $foo->name), $two->render($foo)); | ||
} | ||
|
||
public function testViewArrayAnonymousSectionCallback() { | ||
$tpl = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); | ||
|
||
$data = array( | ||
'name' => 'Bob', | ||
'wrap' => function($text) { | ||
return sprintf('[[%s]]', $text); | ||
} | ||
); | ||
|
||
$this->assertEquals(sprintf('[[%s]]', $data['name']), $tpl->render($data)); | ||
} | ||
} | ||
|
||
class Mustache_Test_FiveThree_Functional_Foo { | ||
public $name = 'Justin'; | ||
public $lorem = 'Lorem ipsum dolor sit amet,'; | ||
public $wrap; | ||
|
||
public function __construct() { | ||
$this->wrap = function($text) { | ||
return sprintf('<em>%s</em>', $text); | ||
}; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Mustache.php. | ||
* | ||
* (c) 2012 Justin Hileman | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* A PHPUnit test case wrapping the Mustache Spec | ||
* | ||
* @group mustache-spec | ||
* @group functional | ||
*/ | ||
class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase { | ||
|
||
private static $mustache; | ||
|
||
public static function setUpBeforeClass() { | ||
self::$mustache = new Mustache_Mustache; | ||
} | ||
|
||
/** | ||
* For some reason data providers can't mark tests skipped, so this test exists | ||
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized. | ||
*/ | ||
public function testSpecInitialized() { | ||
if (!file_exists(dirname(__FILE__).'/../../../../../vendor/spec/specs/')) { | ||
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"'); | ||
} | ||
} | ||
|
||
/** | ||
* @group lambdas | ||
* @dataProvider loadLambdasSpec | ||
*/ | ||
public function testLambdasSpec($desc, $source, $partials, $data, $expected) { | ||
$template = self::loadTemplate($source, $partials); | ||
$this->assertEquals($expected, $template($this->prepareLambdasSpec($data)), $desc); | ||
} | ||
|
||
public function loadLambdasSpec() { | ||
return $this->loadSpec('~lambdas'); | ||
} | ||
|
||
/** | ||
* Extract and lambdafy any 'lambda' values found in the $data array. | ||
*/ | ||
private function prepareLambdasSpec($data) { | ||
foreach ($data as $key => $val) { | ||
if ($key === 'lambda') { | ||
if (!isset($val['php'])) { | ||
$this->markTestSkipped(sprintf('PHP lambda test not implemented for this test.')); | ||
} | ||
|
||
$func = $val['php']; | ||
$data[$key] = function($text = null) use ($func) { | ||
return eval($func); | ||
}; | ||
} else if (is_array($val)) { | ||
$data[$key] = $this->prepareLambdasSpec($val); | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Data provider for the mustache spec test. | ||
* | ||
* Loads YAML files from the spec and converts them to PHPisms. | ||
* | ||
* @access public | ||
* @return array | ||
*/ | ||
private function loadSpec($name) { | ||
$filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml'; | ||
if (!file_exists($filename)) { | ||
return array(); | ||
} | ||
|
||
$data = array(); | ||
$yaml = new sfYamlParser; | ||
$file = file_get_contents($filename); | ||
|
||
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. | ||
if ($name === '~lambdas') { | ||
$file = str_replace(" !code\n", "\n", $file); | ||
} | ||
|
||
$spec = $yaml->parse($file); | ||
|
||
foreach ($spec['tests'] as $test) { | ||
$data[] = array( | ||
$test['name'] . ': ' . $test['desc'], | ||
$test['template'], | ||
isset($test['partials']) ? $test['partials'] : array(), | ||
$test['data'], | ||
$test['expected'], | ||
); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
private static function loadTemplate($source, $partials) { | ||
self::$mustache->setPartials($partials); | ||
|
||
return self::$mustache->loadTemplate($source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.