]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/zordius/lightncandy/tests/mustacheSpecTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / zordius / lightncandy / tests / mustacheSpecTest.php
1 <?php
2
3 require_once('src/lightncandy.php');
4
5 $tmpdir = sys_get_temp_dir();
6
7 class MustacheSpecTest extends PHPUnit_Framework_TestCase
8 {
9     /**
10      * @dataProvider jsonSpecProvider
11      */
12     public function testSpecs($spec)
13     {
14         global $tmpdir;
15
16         $flag = LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_RUNTIMEPARTIAL;
17
18         foreach (Array($flag, $flag | LightnCandy::FLAG_STANDALONE) as $f) {
19             $php = LightnCandy::compile($spec['template'], Array(
20                 'flags' => $f,
21                 'partials' => isset($spec['partials']) ? $spec['partials'] : null,
22                 'basedir' => $tmpdir,
23             ));
24             $renderer = LightnCandy::prepare($php);
25             $this->assertEquals($spec['expected'], $renderer($spec['data']), "[{$spec['file']}.{$spec['name']}]#{$spec['no']}:{$spec['desc']} PHP CODE: $php");
26         }
27     }
28
29     public function jsonSpecProvider()
30     {
31         $ret = Array();
32
33         foreach (glob('specs/mustache/specs/*.json') as $file) {
34             // Skip lambda extension
35             if (preg_match('/lambdas\\.json$/', $file)) {
36                 continue;
37             }
38
39             $i=0;
40             $json = json_decode(file_get_contents($file), true);
41             $ret = array_merge($ret, array_map(function ($d) use ($file, &$i) {
42                 $d['file'] = $file;
43                 $d['no'] = ++$i;
44                 return Array($d);
45             }, $json['tests']));
46         }
47
48         return $ret;
49     }
50 }
51
52
53 ?>