-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ubermichael/master
Remove depreciated Twig_Filter_method
- Loading branch information
Showing
10 changed files
with
247 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,8 @@ | |
"psr-0": { | ||
"Jasny\\Twig": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8" | ||
} | ||
} |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<phpunit bootstrap="./vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="The project's test suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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
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,50 @@ | ||
<?php | ||
|
||
namespace Jasny\Twig; | ||
|
||
use Jasny\Twig\ArrayExtension; | ||
|
||
class ArrayExtensionTest extends PHPUnit_Framework_TestCase { | ||
|
||
private function buildEnv($template) { | ||
$loader = new Twig_Loader_Array(array( | ||
'template' => $template, | ||
)); | ||
$twig = new Twig_Environment($loader); | ||
$twig->addExtension(new ArrayExtension()); | ||
return $twig; | ||
} | ||
|
||
private function process($template, $data = array()) { | ||
$twig = $this->buildEnv($template); | ||
$result = $twig->render('template', $data); | ||
return $result; | ||
} | ||
|
||
private function check($expected, $template, $data = array()) { | ||
$result = $this->process($template, $data); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testSum() { | ||
$data = array(1, 2, 3, 4); | ||
$this->check(10, '{{ data|sum() }}', array('data' => $data)); | ||
} | ||
|
||
public function testProduct() { | ||
$data = array(1, 2, 3, 4); | ||
$this->check(24, '{{ data|product() }}', array('data' => $data)); | ||
} | ||
|
||
public function testValues() { | ||
$data = array(1, 2, 3); | ||
$this->check('1-2-3-', '{% for v in data|values() %}{{v}}-{% endfor %}', array('data' => $data)); | ||
} | ||
|
||
public function testHtmlAttr() { | ||
$data = array('href' => 'foo.html', 'class' => 'big small'); | ||
$this->check('href="foo.html" class="big small"', '{{ data|html_attr|raw }}', array('data' => $data)); | ||
} | ||
|
||
|
||
} |
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,58 @@ | ||
<?php | ||
|
||
namespace Jasny\Twig; | ||
|
||
use Jasny\Twig\DateExtension; | ||
|
||
class DateExtensionTest extends PHPUnit_Framework_TestCase { | ||
|
||
public static function setUpBeforeClass() { | ||
parent::setUpBeforeClass(); | ||
Locale::setDefault("en_CA"); | ||
} | ||
|
||
private function buildEnv($template) { | ||
$loader = new Twig_Loader_Array(array( | ||
'template' => $template, | ||
)); | ||
$twig = new Twig_Environment($loader); | ||
$twig->addExtension(new DateExtension()); | ||
return $twig; | ||
} | ||
|
||
private function process($template, $data = array()) { | ||
$twig = $this->buildEnv($template); | ||
$result = $twig->render('template', $data); | ||
return $result; | ||
} | ||
|
||
private function check($expected, $template) { | ||
$result = $this->process($template); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testLocalDate() { | ||
$this->check('9/20/2015', "{{ '20-09-2015'|localdate() }}"); | ||
} | ||
|
||
public function testLocalDateLong() { | ||
$this->check('September 20, 2015', "{{ '20-09-2015'|localdate('long') }}"); | ||
} | ||
|
||
public function testLocalDateShort() { | ||
$this->check('9/20/15', "{{ '20-09-2015'|localdate('short') }}"); | ||
} | ||
|
||
public function testLocalTime() { | ||
$this->check('11:14 PM', "{{ '23:14:12'|localtime() }}"); | ||
} | ||
|
||
public function testLocalTimeLong() { | ||
$this->check('11:14:12 PM PDT', "{{ '23:14:12'|localtime('long') }}"); | ||
} | ||
|
||
public function testLocalTimeShort() { | ||
$this->check('11:14 PM', "{{ '23:14:12'|localtime('short') }}"); | ||
} | ||
|
||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace Jasny\Twig; | ||
|
||
use Jasny\Twig\PcreExtension; | ||
|
||
class PcreExtensionTest extends PHPUnit_Framework_TestCase { | ||
|
||
private function buildEnv($template) { | ||
$loader = new Twig_Loader_Array(array( | ||
'template' => $template, | ||
)); | ||
$twig = new Twig_Environment($loader); | ||
$twig->addExtension(new PcreExtension()); | ||
return $twig; | ||
} | ||
|
||
private function process($template, $data = array()) { | ||
$twig = $this->buildEnv($template); | ||
$result = $twig->render('template', $data); | ||
return $result; | ||
} | ||
|
||
private function check($expected, $template) { | ||
$result = $this->process($template); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testQuote() { | ||
$this->check('foo\(\)', '{{ "foo()"|preg_quote }}'); | ||
} | ||
|
||
public function testQuoteDelimiter() { | ||
$this->check('foo\@bar', '{{ "foo@bar"|preg_quote("@") }}'); | ||
} | ||
|
||
public function testPregMatch() { | ||
$this->check('YES', '{% if "foo"|preg_match("/oo/") %}YES{% else %}NO{% endif %}'); | ||
} | ||
|
||
public function testPregMatchNo() { | ||
$this->check('NO', '{% if "fod"|preg_match("/oo/") %}YES{% else %}NO{% endif %}'); | ||
} | ||
|
||
/** | ||
* @expectedException Twig_Error_Runtime | ||
*/ | ||
public function testPregMatchError() { | ||
$this->check('NO', '{% if "fod"|preg_match("/o//o/") %}YES{% else %}NO{% endif %}'); | ||
} | ||
|
||
public function testPregGet() { | ||
$this->check('d', '{{ "food"|preg_get("/oo(.)/", 1) }}'); | ||
} | ||
|
||
public function testPregGetDefault() { | ||
$this->check('ood', '{{ "food"|preg_get("/oo(.)/") }}'); | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Jasny\Twig; | ||
|
||
use Jasny\Twig\TextExtension; | ||
|
||
class TextExtensionTest extends PHPUnit_Framework_TestCase { | ||
|
||
private function buildEnv($template) { | ||
$loader = new Twig_Loader_Array(array( | ||
'template' => $template, | ||
)); | ||
$twig = new Twig_Environment($loader); | ||
$twig->addExtension(new TextExtension()); | ||
return $twig; | ||
} | ||
|
||
private function process($template, $data = array()) { | ||
$twig = $this->buildEnv($template); | ||
$result = $twig->render('template', $data); | ||
return $result; | ||
} | ||
|
||
private function check($expected, $template) { | ||
$result = $this->process($template); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testQuote() { | ||
$this->check("<p>foo<br>\nbar</p>", "{{ 'foo\nbar'|paragraph() }}"); | ||
} | ||
|
||
public function testLine() { | ||
$this->check("bar", "{{ 'foo\nbar\nbaz'|line(2) }}"); | ||
} | ||
|
||
public function testLess() { | ||
$this->check("foo..", "{{ 'fooXbarXbaz'|less('..', 'X') }}"); | ||
} | ||
|
||
public function testTruncate() { | ||
$this->check("foo ..", "{{ 'foo bar baz'|truncate(4, '..') }}"); | ||
} | ||
|
||
} |