Skip to content

Commit

Permalink
Fix Twig extensions and Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Poskin committed Sep 26, 2015
1 parent 3a3a21d commit 42c8845
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Tests/Twig/Extension/DateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function testGetName()
public function testGetFilters()
{
$filters = $this->extension->getFilters();
$this->assertInstanceOf('\Twig_SimpleFilter', $filters['time_ago']);
$this->assertEquals(count($filters), 1);
$filter = $filters[0];
$this->assertInstanceOf('\Twig_SimpleFilter', $filter);
$this->assertEquals($filter->getName(), 'time_ago');
}

/**
Expand Down
8 changes: 7 additions & 1 deletion Tests/Twig/Extension/TextExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public function testGetName()
public function testGetFilters()
{
$filters = $this->extension->getFilters();
$this->assertInstanceOf('\Twig_SimpleFilter', $filters['safe_truncate']);
$this->assertEquals(count($filters), 2);
$filter = $filters[0];
$this->assertInstanceOf('\Twig_SimpleFilter', $filter);
$this->assertEquals($filter->getName(), 'camelize');
$filter = $filters[1];
$this->assertInstanceOf('\Twig_SimpleFilter', $filter);
$this->assertEquals($filter->getName(), 'safe_truncate');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Twig/Extension/DateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(TranslatorInterface $translator)
public function getFilters()
{
return array(
'time_ago' => new \Twig_SimpleFilter($this, 'timeAgo'),
new \Twig_SimpleFilter('time_ago', array($this, 'timeAgo')),
);
}

Expand Down
2 changes: 1 addition & 1 deletion Twig/Extension/FacebookExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function initRuntime(\Twig_Environment $environment)
public function getFunctions()
{
return array(
'faceboook_sdk_code' => new \Twig_SimpleFunction($this, 'getFacebookSdkCode', array('is_safe' => array('html'))),
new \Twig_SimpleFunction('faceboook_sdk_code', array($this, 'getFacebookSdkCode'), array('is_safe' => array('html'))),
);
}

Expand Down
6 changes: 3 additions & 3 deletions Twig/Extension/GoogleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function initRuntime(\Twig_Environment $environment)
public function getFunctions()
{
return array(
'analytics_tracking_code' => new \Twig_SimpleFunction($this, 'getAnalyticsTrackingCode', array('is_safe' => array('html'))),
'analytics_tracking_commerce' => new \Twig_SimpleFunction($this, 'getAnalyticsCommerce', array('is_safe' => array('html'))),
'tags_manager_code' => new \Twig_SimpleFunction($this, 'getTagsManagerCode', array('is_safe' => array('html'))),
new \Twig_SimpleFunction('analytics_tracking_code', array($this, 'getAnalyticsTrackingCode'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('analytics_tracking_commerce', array($this, 'getAnalyticsCommerce'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('tags_manager_code', array($this, 'getTagsManagerCode'), array('is_safe' => array('html'))),
);
}

Expand Down
14 changes: 7 additions & 7 deletions Twig/Extension/NavigationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function __construct(NavigationRegistry $registry)
public function getFunctions()
{
return array(
'set_active_paths' => new \Twig_SimpleFunction($this, 'setActivePaths'),
'add_active_path' => new \Twig_SimpleFunction($this, 'addActivePath'),
'get_active_paths' => new \Twig_Function_Method($this, 'getActivePaths'),
'is_active_path' => new \Twig_SimpleFunction($this, 'isActivePath'),
'append_breadcrumb' => new \Twig_SimpleFunction($this, 'appendBreadcrumb'),
'prepend_breadcrumb' => new \Twig_SimpleFunction($this, 'prependBreadcrumb'),
'get_breadcrumbs' => new \Twig_SimpleFunction($this, 'getBreadCrumbs'),
new \Twig_SimpleFunction('set_active_paths', array($this, 'setActivePaths')),
new \Twig_SimpleFunction('add_active_path', array($this, 'addActivePath')),
new \Twig_SimpleFunction('get_active_paths', array($this, 'getActivePaths')),
new \Twig_SimpleFunction('is_active_path', array($this, 'isActivePath')),
new \Twig_SimpleFunction('append_breadcrumb', array($this, 'appendBreadcrumb')),
new \Twig_SimpleFunction('prepend_breadcrumb', array($this, 'prependBreadcrumb')),
new \Twig_SimpleFunction('get_breadcrumbs', array($this, 'getBreadCrumbs')),
);
}

Expand Down
2 changes: 1 addition & 1 deletion Twig/Extension/PaginatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function initRuntime(\Twig_Environment $environment)
public function getFunctions()
{
return array(
'paginator_widget' => new \Twig_SimpleFunction($this, 'renderPaginatorWidget', array('is_safe' => array('html'))),
new \Twig_SimpleFunction('paginator_widget', array($this, 'renderPaginatorWidget'), array('is_safe' => array('html'))),
);
}

Expand Down
14 changes: 7 additions & 7 deletions Twig/Extension/SiteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class SiteExtension extends \Twig_Extension
public function getFunctions()
{
return array(
'prepend_page_title' => new \Twig_SimpleFunction($this, 'prependPageTitle'),
'append_page_title' => new \Twig_SimpleFunction($this, 'appendPageTitle'),
'page_title' => new \Twig_SimpleFunction($this, 'getPageTitle'),
'meta_description' => new \Twig_SimpleFunction($this, 'getMetaDescription'),
'set_meta_description' => new \Twig_SimpleFunction($this, 'setMetaDescription'),
'meta_keywords' => new \Twig_SimpleFunction($this, 'getMetaKeywords'),
'add_meta_keywords' => new \Twig_SimpleFunction($this, 'addMetaKeywords'),
new \Twig_SimpleFunction('prepend_page_title', array($this, 'prependPageTitle')),
new \Twig_SimpleFunction('append_page_title', array($this, 'appendPageTitle')),
new \Twig_SimpleFunction('page_title', array($this, 'getPageTitle')),
new \Twig_SimpleFunction('meta_description', array($this, 'getMetaDescription')),
new \Twig_SimpleFunction('set_meta_description', array($this, 'setMetaDescription')),
new \Twig_SimpleFunction('meta_keywords', array($this, 'getMetaKeywords')),
new \Twig_SimpleFunction('add_meta_keywords', array($this, 'addMetaKeywords')),
);
}

Expand Down
4 changes: 2 additions & 2 deletions Twig/Extension/TextExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function getName()
public function getFilters()
{
return array(
'camelize' => new \Twig_SimpleFilter($this, 'camelize', array('is_safe' => array('html'))),
'safe_truncate' => new \Twig_SimpleFilter($this, 'safeTruncate', array('needs_environment' => true, 'is_safe' => array('html'))),
new \Twig_SimpleFilter('camelize', array($this, 'camelize'), array('is_safe' => array('html'))),
new \Twig_SimpleFilter('safe_truncate', array($this, 'safeTruncate'), array('needs_environment' => true, 'is_safe' => array('html'))),
);
}

Expand Down

0 comments on commit 42c8845

Please sign in to comment.