Merge pull request #695 from Vivalldi/feature/tests

Adding Tests - On going
This commit is contained in:
Andy Miller
2016-02-21 21:18:45 -07:00
3 changed files with 179 additions and 5 deletions

View File

@@ -218,7 +218,7 @@ class TwigExtension extends \Twig_Extension
* {{ 'CamelCased'|underscorize }} => camel_cased
* {{ 'Something Text'|hyphenize }} => something-text
* {{ 'something_text_to_read'|humanize }} => "Something text to read"
* {{ '181'|monthize }} => 6
* {{ '181'|monthize }} => 5
* {{ '10'|ordinalize }} => 10th
*
* @param string $action

View File

@@ -105,22 +105,41 @@ class InflectorTest extends \Codeception\TestCase\Test
public function testTableize()
{
$this->assertSame('people', $this->inflector->tableize('Person'));
$this->assertSame('pages', $this->inflector->tableize('Page'));
$this->assertSame('blog_pages', $this->inflector->tableize('BlogPage'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('adminDependency'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('admin-dependency'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('admin_dependency'));
}
public function testClassify()
{
$this->assertSame('Person', $this->inflector->classify('people'));
$this->assertSame('Page', $this->inflector->classify('pages'));
$this->assertSame('BlogPage', $this->inflector->classify('blog_pages'));
$this->assertSame('AdminDependency', $this->inflector->classify('admin_dependencies'));
}
public function testOrdinalize()
{
$this->assertSame('1st', $this->inflector->ordinalize(1));
$this->assertSame('2nd', $this->inflector->ordinalize(2));
$this->assertSame('3rd', $this->inflector->ordinalize(3));
$this->assertSame('4th', $this->inflector->ordinalize(4));
$this->assertSame('5th', $this->inflector->ordinalize(5));
$this->assertSame('16th', $this->inflector->ordinalize(16));
$this->assertSame('51st', $this->inflector->ordinalize(51));
$this->assertSame('111th', $this->inflector->ordinalize(111));
$this->assertSame('123rd', $this->inflector->ordinalize(123));
}
public function testMonthize()
{
$this->assertSame(0, $this->inflector->monthize(10));
$this->assertSame(1, $this->inflector->monthize(30));
$this->assertSame(1, $this->inflector->monthize(41));
$this->assertSame(11, $this->inflector->monthize(365));
}
}

View File

@@ -21,6 +21,157 @@ class TwigExtensionTest extends \Codeception\TestCase\Test
$this->twig_ext = new TwigExtension();
}
public function testInflectorFilter()
{
$this->assertSame('people', $this->twig_ext->inflectorFilter('plural', 'person'));
$this->assertSame('shoe', $this->twig_ext->inflectorFilter('singular', 'shoes'));
$this->assertSame('Welcome Page', $this->twig_ext->inflectorFilter('title', 'welcome page'));
$this->assertSame('SendEmail', $this->twig_ext->inflectorFilter('camel', 'send_email'));
$this->assertSame('camel_cased', $this->twig_ext->inflectorFilter('underscor', 'CamelCased'));
$this->assertSame('something-text', $this->twig_ext->inflectorFilter('hyphen', 'Something Text'));
$this->assertSame('Something text to read', $this->twig_ext->inflectorFilter('human', 'something_text_to_read'));
$this->assertSame(5, $this->twig_ext->inflectorFilter('month', 181));
$this->assertSame('10th', $this->twig_ext->inflectorFilter('ordinal', 10));
}
public function testMd5Filter()
{
$this->assertSame(md5('grav'), $this->twig_ext->md5Filter('grav'));
$this->assertSame(md5('devs@getgrav.org'), $this->twig_ext->md5Filter('devs@getgrav.org'));
}
public function testKsortFilter()
{
$object = array("name"=>"Bob","age"=>8,"colour"=>"red");
$this->assertSame(array("age"=>8,"colour"=>"red","name"=>"Bob"), $this->twig_ext->ksortFilter($object));
}
public function testContainsFilter()
{
$this->assertTrue($this->twig_ext->containsFilter('grav','grav'));
$this->assertTrue($this->twig_ext->containsFilter('So, I found this new cms, called grav, and it\'s pretty awesome guys','grav'));
}
public function testNicetimeFilter()
{
$now = time();
$threeSeconds = time() - (3);
$threeMinutes = time() - (60*3);
$threeHours = time() - (60*60*3);
$threeDays = time() - (60*60*24*3);
$threeMonths = time() - (60*60*24*30*3);
$threeYears = time() - (60*60*24*365*3);
$measures = ['seconds','minutes','hours','days','months','years'];
$this->assertSame('No date provided', $this->twig_ext->nicetimeFilter(null));
for ($i=0; $i<count($measures); $i++) {
$time = 'three' . ucfirst($measures[$i]);
$this->assertSame('3 ' . $measures[$i] . ' ago', $this->twig_ext->nicetimeFilter($$time));
}
$this->assertSame('3 secs ago', $this->twig_ext->nicetimeFilter($threeSeconds, false));
}
public function testSafeEmailFilter()
{
$this->assertSame('&#100;&#101;&#118;&#115;&#64;&#103;&#101;&#116;&#103;&#114;&#97;&#118;&#46;&#111;&#114;&#103;', $this->twig_ext->safeEmailFilter('devs@getgrav.org'));
$this->assertSame('&#115;&#111;&#109;&#101;&#111;&#110;&#101;&#64;&#101;&#120;&#97;&#109;&#112;&#108;&#101;&#46;&#99;&#111;&#109;', $this->twig_ext->safeEmailFilter('someone@example.com'));
}
public function testRandomizeFilter()
{
$array = [1,2,3,4,5];
$this->assertContains(2, $this->twig_ext->randomizeFilter($array));
$this->assertSame($array, $this->twig_ext->randomizeFilter($array, 5));
$this->assertSame($array[0], $this->twig_ext->randomizeFilter($array, 1)[0]);
$this->assertSame($array[3], $this->twig_ext->randomizeFilter($array, 4)[3]);
$this->assertSame($array[1], $this->twig_ext->randomizeFilter($array, 4)[1]);
}
public function testModulusFilter()
{
$this->assertSame(3, $this->twig_ext->modulusFilter(3,4));
$this->assertSame(1, $this->twig_ext->modulusFilter(11,2));
$this->assertSame(0, $this->twig_ext->modulusFilter(10,2));
$this->assertSame(2, $this->twig_ext->modulusFilter(10,4));
}
public function testAbsoluteUrlFilter()
{
}
public function testMarkdownFilter()
{
}
public function testStartsWithFilter()
{
}
public function testEndsWithFilter()
{
}
public function testDefinedDefaultFilter()
{
}
public function testRtrimFilter()
{
}
public function testLtrimFilter()
{
}
public function testRepeatFunc()
{
}
public function testUrlFunc()
{
}
public function testEvaluateFunc()
{
}
public function testDump()
{
}
public function testGistFunc()
{
}
public function testRandomStringFunc()
{
}
public function testPadFilter()
{
}
public function testArrayFunc()
{
}
public function testArrayKeyValue()
{
$this->assertSame(['meat' => 'steak'],
@@ -29,4 +180,8 @@ class TwigExtensionTest extends \Codeception\TestCase\Test
$this->twig_ext->arrayKeyValueFunc('meat', 'steak', ['fruit' => 'apple']));
}
public function stringFunc()
{
}
}