Move examples into the test fixtures.
This commit is contained in:
@@ -35,18 +35,16 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* Data provider for testExamples method.
|
||||
*
|
||||
* Assumes that an `examples` directory exists inside parent directory.
|
||||
* Loads examples from the test fixtures directory.
|
||||
*
|
||||
* This examples directory should contain any number of subdirectories, each of which contains
|
||||
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
|
||||
* (.txt).
|
||||
*
|
||||
* This whole mess will be refined later to be more intuitive and less prescriptive, but it'll
|
||||
* do for now. Especially since it means we can have unit tests :)
|
||||
* (.txt). Optionally, the directory may contain a folder full of partials.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExamples() {
|
||||
$path = realpath(dirname(__FILE__).'/../../../../examples');
|
||||
$path = realpath(dirname(__FILE__).'/../../../fixtures/examples');
|
||||
$examples = array();
|
||||
|
||||
$handle = opendir($path);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class ChildContext {
|
||||
public $parent = array(
|
||||
'child' => 'child works',
|
||||
);
|
||||
|
||||
public $grandparent = array(
|
||||
'parent' => array(
|
||||
'child' => 'grandchild works',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<h1>{{#parent}}{{child}}{{/parent}}</h1>
|
||||
<h2>{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}</h2>
|
||||
@@ -0,0 +1,2 @@
|
||||
<h1>child works</h1>
|
||||
<h2>grandchild works</h2>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class Comments {
|
||||
public function title() {
|
||||
return 'A Comedy of Errors';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<h1>{{title}}{{! just something interesting... #or ^not... }}</h1>
|
||||
@@ -0,0 +1 @@
|
||||
<h1>A Comedy of Errors</h1>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<h1>{{header}}</h1>
|
||||
{{#notEmpty}}
|
||||
<ul>
|
||||
{{#item}}
|
||||
{{#current}}
|
||||
<li><strong>{{name}}</strong></li>
|
||||
{{/current}}
|
||||
{{^current}}
|
||||
<li><a href="{{url}}">{{name}}</a></li>
|
||||
{{/current}}
|
||||
{{/item}}
|
||||
</ul>
|
||||
{{/notEmpty}}
|
||||
{{#isEmpty}}
|
||||
<p>The list is empty.</p>
|
||||
{{/isEmpty}}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class Complex {
|
||||
public $header = 'Colors';
|
||||
|
||||
public $item = array(
|
||||
array('name' => 'red', 'current' => true, 'url' => '#Red'),
|
||||
array('name' => 'green', 'current' => false, 'url' => '#Green'),
|
||||
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
||||
);
|
||||
|
||||
public function notEmpty() {
|
||||
return !($this->isEmpty());
|
||||
}
|
||||
|
||||
public function isEmpty() {
|
||||
return count($this->item) === 0;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<h1>Colors</h1>
|
||||
<ul>
|
||||
<li><strong>red</strong></li>
|
||||
<li><a href="#Green">green</a></li>
|
||||
<li><a href="#Blue">blue</a></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Delimiters {
|
||||
public $start = "It worked the first time.";
|
||||
|
||||
public function middle() {
|
||||
return array(
|
||||
array('item' => "And it worked the second time."),
|
||||
array('item' => "As well as the third."),
|
||||
);
|
||||
}
|
||||
|
||||
public $final = "Then, surprisingly, it worked the final time.";
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{{=<% %>=}}
|
||||
* <% start %>
|
||||
<%=| |=%>
|
||||
|# middle |
|
||||
* | item |
|
||||
|/ middle |
|
||||
|={{ }}=|
|
||||
* {{ final }}
|
||||
@@ -0,0 +1,4 @@
|
||||
* It worked the first time.
|
||||
* And it worked the second time.
|
||||
* As well as the third.
|
||||
* Then, surprisingly, it worked the final time.
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class DotNotation {
|
||||
public $person = array(
|
||||
'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
|
||||
'age' => 24,
|
||||
'hometown' => array(
|
||||
'city' => 'Cincinnati',
|
||||
'state' => 'OH',
|
||||
)
|
||||
);
|
||||
|
||||
public $normal = 'Normal';
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
* {{person.name.first}} {{person.name.last}}
|
||||
* {{person.age}}
|
||||
* {{person.hometown.city}}, {{person.hometown.state}}
|
||||
* {{normal}}
|
||||
@@ -0,0 +1,4 @@
|
||||
* Chris Firescythe
|
||||
* 24
|
||||
* Cincinnati, OH
|
||||
* Normal
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class DoubleSection {
|
||||
public function t() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public $two = "second";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{{#t}}
|
||||
* first
|
||||
{{/t}}
|
||||
* {{two}}
|
||||
{{#t}}
|
||||
* third
|
||||
{{/t}}
|
||||
@@ -0,0 +1,3 @@
|
||||
* first
|
||||
* second
|
||||
* third
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Escaped {
|
||||
public $title = '"Bear" > "Shark"';
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<h1>{{title}}</h1>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<h1>"Bear" > "Shark"</h1>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class GrandParentContext {
|
||||
public $grand_parent_id = 'grand_parent1';
|
||||
public $parent_contexts = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
|
||||
array('child_id' => 'parent1-child1'),
|
||||
array('child_id' => 'parent1-child2')
|
||||
));
|
||||
|
||||
$parent2 = new stdClass();
|
||||
$parent2->parent_id = 'parent2';
|
||||
$parent2->child_contexts = array(
|
||||
array('child_id' => 'parent2-child1'),
|
||||
array('child_id' => 'parent2-child2')
|
||||
);
|
||||
|
||||
$this->parent_contexts[] = $parent2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{{grand_parent_id}}
|
||||
{{#parent_contexts}}
|
||||
{{parent_id}} ({{grand_parent_id}})
|
||||
{{#child_contexts}}
|
||||
{{child_id}} ({{parent_id}} << {{grand_parent_id}})
|
||||
{{/child_contexts}}
|
||||
{{/parent_contexts}}
|
||||
@@ -0,0 +1,7 @@
|
||||
grand_parent1
|
||||
parent1 (grand_parent1)
|
||||
parent1-child1 (parent1 << grand_parent1)
|
||||
parent1-child2 (parent1 << grand_parent1)
|
||||
parent2 (grand_parent1)
|
||||
parent2-child1 (parent2 << grand_parent1)
|
||||
parent2-child2 (parent2 << grand_parent1)
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class I18n {
|
||||
|
||||
// Variable to be interpolated
|
||||
public $name = 'Bob';
|
||||
|
||||
// Add a {{#__}} lambda for i18n
|
||||
public $__ = array(__CLASS__, '__trans');
|
||||
|
||||
// A *very* small i18n dictionary :)
|
||||
private static $dictionary = array(
|
||||
'Hello.' => 'Hola.',
|
||||
'My name is {{ name }}.' => 'Me llamo {{ name }}.',
|
||||
);
|
||||
|
||||
public static function __trans($text) {
|
||||
return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{{#__}}Hello.{{/__}} {{#__}}My name is {{ name }}.{{/__}}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
Hola. Me llamo Bob.
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class ImplicitIterator {
|
||||
public $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{{#data}}
|
||||
* {{.}}
|
||||
{{/data}}
|
||||
@@ -0,0 +1,5 @@
|
||||
* Donkey Kong
|
||||
* Luigi
|
||||
* Mario
|
||||
* Peach
|
||||
* Yoshi
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class InvertedDoubleSection {
|
||||
public $t = false;
|
||||
public $two = 'second';
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{{^t}}
|
||||
* first
|
||||
{{/t}}
|
||||
* {{two}}
|
||||
{{^t}}
|
||||
* third
|
||||
{{/t}}
|
||||
@@ -0,0 +1,3 @@
|
||||
* first
|
||||
* second
|
||||
* third
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class InvertedSection {
|
||||
public $repo = array();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{{#repo}}
|
||||
<b>{{name}}</b>
|
||||
{{/repo}}
|
||||
{{^repo}}
|
||||
No repos :(
|
||||
{{/repo}}
|
||||
@@ -0,0 +1 @@
|
||||
No repos :(
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class Partials {
|
||||
public $page = array(
|
||||
'title' => 'Page Title',
|
||||
'subtitle' => 'Page Subtitle',
|
||||
'content' => 'Lorem ipsum dolor sit amet.',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<div>
|
||||
{{> header }}
|
||||
|
||||
<div>
|
||||
{{ page.content }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
<div>
|
||||
<h1>Page Title</h1>
|
||||
<h2>Page Subtitle</h2>
|
||||
|
||||
<div>
|
||||
Lorem ipsum dolor sit amet.
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,4 @@
|
||||
{{# page }}
|
||||
<h1>{{ title }}</h1>
|
||||
<h2>{{ subtitle }}</h2>
|
||||
{{/ page }}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class RecursivePartials {
|
||||
public $name = 'George';
|
||||
public $child = array(
|
||||
'name' => 'Dan',
|
||||
'child' => array(
|
||||
'name' => 'Justin',
|
||||
'child' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
> {{ name }}{{#child}}{{>child}}{{/child}}
|
||||
@@ -0,0 +1 @@
|
||||
{{name}}{{#child}}{{>child}}{{/child}}
|
||||
@@ -0,0 +1 @@
|
||||
George > Dan > Justin
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class SectionIteratorObjects {
|
||||
public $start = "It worked the first time.";
|
||||
|
||||
protected $_data = array(
|
||||
array('item' => 'And it worked the second time.'),
|
||||
array('item' => 'As well as the third.'),
|
||||
);
|
||||
|
||||
public function middle() {
|
||||
return new ArrayIterator($this->_data);
|
||||
}
|
||||
|
||||
public $final = "Then, surprisingly, it worked the final time.";
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
* {{ start }}
|
||||
{{# middle }}
|
||||
* {{ item }}
|
||||
{{/ middle }}
|
||||
* {{ final }}
|
||||
@@ -0,0 +1,4 @@
|
||||
* It worked the first time.
|
||||
* And it worked the second time.
|
||||
* As well as the third.
|
||||
* Then, surprisingly, it worked the final time.
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class SectionMagicObjects {
|
||||
public $start = "It worked the first time.";
|
||||
|
||||
public function middle() {
|
||||
return new MagicObject();
|
||||
}
|
||||
|
||||
public $final = "Then, surprisingly, it worked the final time.";
|
||||
}
|
||||
|
||||
class MagicObject {
|
||||
protected $_data = array(
|
||||
'foo' => 'And it worked the second time.',
|
||||
'bar' => 'As well as the third.'
|
||||
);
|
||||
|
||||
public function __get($key) {
|
||||
return isset($this->_data[$key]) ? $this->_data[$key] : NULL;
|
||||
}
|
||||
|
||||
public function __isset($key) {
|
||||
return isset($this->_data[$key]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
* {{ start }}
|
||||
{{# middle }}
|
||||
* {{ foo }}
|
||||
* {{ bar }}
|
||||
{{/ middle }}
|
||||
* {{ final }}
|
||||
@@ -0,0 +1,4 @@
|
||||
* It worked the first time.
|
||||
* And it worked the second time.
|
||||
* As well as the third.
|
||||
* Then, surprisingly, it worked the final time.
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class SectionObjects {
|
||||
public $start = "It worked the first time.";
|
||||
|
||||
public function middle() {
|
||||
return new SectionObject;
|
||||
}
|
||||
|
||||
public $final = "Then, surprisingly, it worked the final time.";
|
||||
}
|
||||
|
||||
class SectionObject {
|
||||
public $foo = 'And it worked the second time.';
|
||||
public $bar = 'As well as the third.';
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
* {{ start }}
|
||||
{{# middle }}
|
||||
* {{ foo }}
|
||||
* {{ bar }}
|
||||
{{/ middle }}
|
||||
* {{ final }}
|
||||
@@ -0,0 +1,4 @@
|
||||
* It worked the first time.
|
||||
* And it worked the second time.
|
||||
* As well as the third.
|
||||
* Then, surprisingly, it worked the final time.
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Sections {
|
||||
public $start = "It worked the first time.";
|
||||
|
||||
public function middle() {
|
||||
return array(
|
||||
array('item' => "And it worked the second time."),
|
||||
array('item' => "As well as the third."),
|
||||
);
|
||||
}
|
||||
|
||||
public $final = "Then, surprisingly, it worked the final time.";
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
* {{ start }}
|
||||
{{# middle }}
|
||||
* {{ item }}
|
||||
{{/ middle }}
|
||||
* {{ final }}
|
||||
@@ -0,0 +1,4 @@
|
||||
* It worked the first time.
|
||||
* And it worked the second time.
|
||||
* As well as the third.
|
||||
* Then, surprisingly, it worked the final time.
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class SectionsNested {
|
||||
public $name = 'Little Mac';
|
||||
|
||||
public function enemies() {
|
||||
return array(
|
||||
array(
|
||||
'name' => 'Von Kaiser',
|
||||
'enemies' => array(
|
||||
array('name' => 'Super Macho Man'),
|
||||
array('name' => 'Piston Honda'),
|
||||
array('name' => 'Mr. Sandman'),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => 'Mike Tyson',
|
||||
'enemies' => array(
|
||||
array('name' => 'Soda Popinski'),
|
||||
array('name' => 'King Hippo'),
|
||||
array('name' => 'Great Tiger'),
|
||||
array('name' => 'Glass Joe'),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => 'Don Flamenco',
|
||||
'enemies' => array(
|
||||
array('name' => 'Bald Bull'),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
Enemies of {{ name }}:
|
||||
{{# enemies }}
|
||||
{{ name }} ... who also has enemies:
|
||||
{{# enemies }}
|
||||
--> {{ name }}
|
||||
{{/ enemies }}
|
||||
{{/ enemies }}
|
||||
@@ -0,0 +1,12 @@
|
||||
Enemies of Little Mac:
|
||||
Von Kaiser ... who also has enemies:
|
||||
--> Super Macho Man
|
||||
--> Piston Honda
|
||||
--> Mr. Sandman
|
||||
Mike Tyson ... who also has enemies:
|
||||
--> Soda Popinski
|
||||
--> King Hippo
|
||||
--> Great Tiger
|
||||
--> Glass Joe
|
||||
Don Flamenco ... who also has enemies:
|
||||
--> Bald Bull
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class Simple {
|
||||
public $name = "Chris";
|
||||
public $value = 10000;
|
||||
|
||||
public function taxed_value() {
|
||||
return $this->value - ($this->value * 0.4);
|
||||
}
|
||||
|
||||
public $in_ca = true;
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
Hello {{name}}
|
||||
You have just won ${{value}}!
|
||||
{{#in_ca}}
|
||||
Well, ${{ taxed_value }}, after taxes.
|
||||
{{/in_ca}}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Hello Chris
|
||||
You have just won $10000!
|
||||
Well, $6000, after taxes.
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Unescaped {
|
||||
public $title = "Bear > Shark";
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<h1>{{{title}}}</h1>
|
||||
@@ -0,0 +1 @@
|
||||
<h1>Bear > Shark</h1>
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class UTF8 {
|
||||
public $test = '中文又来啦';
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<h1>中文 {{test}}</h1>
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
<h1>中文 中文又来啦</h1>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class UTF8Unescaped {
|
||||
public $test = '中文又来啦';
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<h1>中文 {{{test}}}</h1>
|
||||
@@ -0,0 +1 @@
|
||||
<h1>中文 中文又来啦</h1>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Whitespace test for tag names.
|
||||
*
|
||||
* Per http://github.com/janl/mustache.js/issues/issue/34/#comment_244396
|
||||
* tags should strip leading and trailing whitespace in key names.
|
||||
*
|
||||
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
|
||||
*/
|
||||
class Whitespace {
|
||||
public $foo = 'alpha';
|
||||
|
||||
public $bar = 'beta';
|
||||
|
||||
public function baz() {
|
||||
return 'gamma';
|
||||
}
|
||||
|
||||
public function qux() {
|
||||
return array(
|
||||
array('key with space' => 'A'),
|
||||
array('key with space' => 'B'),
|
||||
array('key with space' => 'C'),
|
||||
array('key with space' => 'D'),
|
||||
array('key with space' => 'E'),
|
||||
array('key with space' => 'F'),
|
||||
array('key with space' => 'G'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
* {{.}}
|
||||
@@ -0,0 +1,10 @@
|
||||
{{^ inverted section test }}
|
||||
These are some things:
|
||||
{{/inverted section test }}
|
||||
* {{ foo }}
|
||||
* {{ bar}}
|
||||
* {{ baz }}
|
||||
{{# qux }}
|
||||
* {{ key with space }}
|
||||
{{/ qux }}
|
||||
{{#qux}}.{{/qux}}
|
||||
@@ -0,0 +1,12 @@
|
||||
These are some things:
|
||||
* alpha
|
||||
* beta
|
||||
* gamma
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
* D
|
||||
* E
|
||||
* F
|
||||
* G
|
||||
.......
|
||||
Reference in New Issue
Block a user