This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
forked from sveneisenschmidt/gravatar-php
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Twig extension for Twig 2. Add unit tests
- Loading branch information
Showing
4 changed files
with
56 additions
and
4 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8" | ||
"phpunit/phpunit": "^4.8", | ||
"twig/twig": "^2.4" | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Gravatar\Tests; | ||
|
||
use Gravatar\Service; | ||
use Gravatar\Extension\Twig\GravatarExtension; | ||
|
||
use Twig_Environment; | ||
use Twig_Loader_Array; | ||
|
||
class TwigExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testRegisterExtension() | ||
{ | ||
$twig = new Twig_Environment(new Twig_Loader_Array(array())); | ||
$gravatarService = new Service(); | ||
$twig->addExtension(new GravatarExtension($gravatarService)); | ||
} | ||
|
||
public function testRenderGravatarUrl() | ||
{ | ||
$twig = new Twig_Environment(new Twig_Loader_Array(array( | ||
'index.html' => '{{gravatar(email, {"size": 50})}}', | ||
))); | ||
|
||
$gravatarService = new Service(); | ||
|
||
$twig->addExtension(new GravatarExtension($gravatarService)); | ||
|
||
$url = $twig->render('index.html', array( | ||
'email' => 'user@example.com' | ||
)); | ||
|
||
$this->assertEquals('http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?s=50&r=g', $url); | ||
} | ||
|
||
public function testRenderGravatarExists() | ||
{ | ||
$twig = new Twig_Environment(new Twig_Loader_Array(array( | ||
'exists' => '{{gravatar_exist(email)}}', | ||
))); | ||
|
||
$gravatarService = new Service(); | ||
|
||
$twig->addExtension(new GravatarExtension($gravatarService)); | ||
|
||
$this->assertEquals("", $twig->render('exists', array('email' => 'user@example.com'))); | ||
$this->assertEquals("1", $twig->render('exists', array('email' => 'm@michaelheap.com'))); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../src/Gravatar/Service.php'; | ||
require_once __DIR__ . '/../vendor/autoload.php'; |