forked from netgen/TagsBundle
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 netgen#50 from MarioBlazek/templating_tests
Templating tests
- Loading branch information
Showing
7 changed files
with
338 additions
and
2 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
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,41 @@ | ||
<?php | ||
|
||
namespace Netgen\TagsBundle\Tests\Templating\Twig; | ||
|
||
use Netgen\TagsBundle\Templating\Twig\AdminGlobalVariable; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AdminGlobalVariableTest extends TestCase | ||
{ | ||
/** | ||
* @var \Netgen\TagsBundle\Templating\Twig\AdminGlobalVariable | ||
*/ | ||
protected $adminGlobalVariable; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $template; | ||
|
||
public function setUp() | ||
{ | ||
$this->adminGlobalVariable = new AdminGlobalVariable(); | ||
$this->template = 'AcmeBundle::pagelayout.html.twig'; | ||
} | ||
|
||
public function testInstanceOfGlobalAdminVariable() | ||
{ | ||
$this->assertInstanceOf(AdminGlobalVariable::class, $this->adminGlobalVariable); | ||
} | ||
|
||
public function testGetAndSetPageLayoutTemplate() | ||
{ | ||
$this->assertNull($this->adminGlobalVariable->getPageLayoutTemplate()); | ||
|
||
$this->adminGlobalVariable->setPageLayoutTemplate($this->template); | ||
$this->assertEquals($this->template, $this->adminGlobalVariable->getPageLayoutTemplate()); | ||
|
||
$this->adminGlobalVariable->setPageLayoutTemplate(); | ||
$this->assertNull($this->adminGlobalVariable->getPageLayoutTemplate()); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace Netgen\TagsBundle\Tests\Templating\Twig\Extension; | ||
|
||
use Netgen\TagsBundle\Templating\Twig\AdminGlobalVariable; | ||
use Netgen\TagsBundle\Templating\Twig\Extension\AdminExtension; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig_Extension; | ||
use Twig_Extension_GlobalsInterface; | ||
|
||
class AdminExtensionTest extends TestCase | ||
{ | ||
/** | ||
* @var \Netgen\TagsBundle\Templating\Twig\Extension\AdminExtension | ||
*/ | ||
protected $extension; | ||
|
||
/** | ||
* @var \Netgen\TagsBundle\Templating\Twig\AdminGlobalVariable | ||
*/ | ||
protected $adminGlobalVariable; | ||
|
||
public function setUp() | ||
{ | ||
$this->adminGlobalVariable = new AdminGlobalVariable(); | ||
$this->extension = new AdminExtension($this->adminGlobalVariable); | ||
} | ||
|
||
public function testInstanceOfTwigExtension() | ||
{ | ||
$this->assertInstanceOf(Twig_Extension::class, $this->extension); | ||
} | ||
|
||
public function testInstanceOfTwigExtensionGlobalsInterface() | ||
{ | ||
$this->assertInstanceOf(Twig_Extension_GlobalsInterface::class, $this->extension); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$this->assertEquals('Netgen\TagsBundle\Templating\Twig\Extension\AdminExtension', $this->extension->getName()); | ||
} | ||
|
||
public function testGetGlobals() | ||
{ | ||
$this->assertEquals(array('eztags_admin' => $this->adminGlobalVariable), $this->extension->getGlobals()); | ||
} | ||
} |
222 changes: 222 additions & 0 deletions
222
Tests/Templating/Twig/Extension/NetgenTagsExtensionTest.php
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,222 @@ | ||
<?php | ||
|
||
namespace Netgen\TagsBundle\Tests\Templating\Twig\Extension; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Language; | ||
use eZ\Publish\Core\Base\Exceptions\NotFoundException; | ||
use eZ\Publish\Core\Helper\TranslationHelper; | ||
use eZ\Publish\Core\Repository\ContentTypeService; | ||
use eZ\Publish\Core\Repository\LanguageService; | ||
use eZ\Publish\Core\Repository\Values\ContentType\ContentType; | ||
use Netgen\TagsBundle\API\Repository\Values\Tags\Tag; | ||
use Netgen\TagsBundle\Core\Repository\TagsService; | ||
use Netgen\TagsBundle\Templating\Twig\Extension\NetgenTagsExtension; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig_Extension; | ||
use Twig_SimpleFunction; | ||
|
||
class NetgenTagsExtensionTest extends TestCase | ||
{ | ||
/** | ||
* @var \Netgen\TagsBundle\Templating\Twig\Extension\NetgenTagsExtension | ||
*/ | ||
protected $extension; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $tagsService; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $translationHelper; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $languageService; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $contentTypeService; | ||
|
||
/** | ||
* @var \Netgen\TagsBundle\API\Repository\Values\Tags\Tag | ||
*/ | ||
protected $tag; | ||
|
||
/** | ||
* @var \eZ\Publish\Core\Repository\Values\ContentType\ContentType | ||
*/ | ||
protected $contentType; | ||
|
||
public function setUp() | ||
{ | ||
$this->tagsService = $this->getMockBuilder(TagsService::class) | ||
->disableOriginalConstructor() | ||
->setMethods(array('loadTag')) | ||
->getMock(); | ||
|
||
$this->translationHelper = $this->getMockBuilder(TranslationHelper::class) | ||
->disableOriginalConstructor() | ||
->setMethods(array('getTranslatedByMethod')) | ||
->getMock(); | ||
|
||
$this->languageService = $this->getMockBuilder(LanguageService::class) | ||
->disableOriginalConstructor() | ||
->setMethods(array('loadLanguage')) | ||
->getMock(); | ||
|
||
$this->contentTypeService = $this->getMockBuilder(ContentTypeService::class) | ||
->disableOriginalConstructor() | ||
->setMethods(array('loadContentType')) | ||
->getMock(); | ||
|
||
$this->extension = new NetgenTagsExtension( | ||
$this->tagsService, | ||
$this->translationHelper, | ||
$this->languageService, | ||
$this->contentTypeService | ||
); | ||
|
||
$this->tag = new Tag(); | ||
$this->contentType = new ContentType(array('fieldDefinitions' => array())); | ||
} | ||
|
||
public function testInstanceOfTwigExtension() | ||
{ | ||
$this->assertInstanceOf(Twig_Extension::class, $this->extension); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$this->assertEquals(NetgenTagsExtension::class, $this->extension->getName()); | ||
} | ||
|
||
public function testGetFunctions() | ||
{ | ||
$functions = array( | ||
new Twig_SimpleFunction( | ||
'netgen_tags_tag_keyword', | ||
array($this->extension, 'getTagKeyword') | ||
), | ||
new Twig_SimpleFunction( | ||
'netgen_tags_language_name', | ||
array($this->extension, 'getLanguageName') | ||
), | ||
new Twig_SimpleFunction( | ||
'netgen_tags_content_type_name', | ||
array($this->extension, 'getContentTypeName') | ||
), | ||
); | ||
|
||
$this->assertEquals($functions, $this->extension->getFunctions()); | ||
} | ||
|
||
public function testGetTagKeywordWithNotFoundException() | ||
{ | ||
$this->tagsService->expects($this->once()) | ||
->method('loadTag') | ||
->willThrowException(new NotFoundException('tag', 'tag')); | ||
|
||
$this->assertEmpty($this->extension->getTagKeyword(1)); | ||
} | ||
|
||
public function testGetTagKeywordWithNonTagArgument() | ||
{ | ||
$translated = 'translated'; | ||
|
||
$this->tagsService->expects($this->once()) | ||
->method('loadTag') | ||
->willReturn($this->tag); | ||
|
||
$this->translationHelper->expects($this->once()) | ||
->method('getTranslatedByMethod') | ||
->with($this->tag) | ||
->willReturn($translated); | ||
|
||
$this->assertEquals($translated, $this->extension->getTagKeyword(1)); | ||
} | ||
|
||
public function testGetTagKeywordWithTagArgument() | ||
{ | ||
$translated = 'translated'; | ||
|
||
$this->tagsService->expects($this->never()) | ||
->method('loadTag'); | ||
|
||
$this->translationHelper->expects($this->once()) | ||
->method('getTranslatedByMethod') | ||
->with($this->tag) | ||
->willReturn($translated); | ||
|
||
$this->assertEquals($translated, $this->extension->getTagKeyword($this->tag)); | ||
} | ||
|
||
public function testGetLanguageName() | ||
{ | ||
$language = new Language( | ||
array( | ||
'id' => 123, | ||
'languageCode' => 'eng-EU', | ||
'name' => 'English', | ||
) | ||
); | ||
|
||
$this->languageService->expects($this->once()) | ||
->method('loadLanguage') | ||
->with($language->languageCode) | ||
->willReturn($language); | ||
|
||
$name = $this->extension->getLanguageName($language->languageCode); | ||
|
||
$this->assertEquals($language->name, $name); | ||
} | ||
|
||
public function testGetContentTypeNameWithNotFoundException() | ||
{ | ||
$contentType = 'content_type'; | ||
|
||
$this->contentTypeService->expects($this->once()) | ||
->method('loadContentType') | ||
->with($contentType) | ||
->willThrowException(new NotFoundException($contentType, $contentType)); | ||
|
||
$this->translationHelper->expects($this->never()) | ||
->method('getTranslatedByMethod'); | ||
|
||
$this->assertEmpty($this->extension->getContentTypeName('content_type')); | ||
} | ||
|
||
public function testGetContentTypeNameWithNonContentTypeAsArgument() | ||
{ | ||
$contentType = 'content_type'; | ||
|
||
$this->contentTypeService->expects($this->once()) | ||
->method('loadContentType') | ||
->with($contentType) | ||
->willReturn($this->contentType); | ||
|
||
$this->translationHelper->expects($this->once()) | ||
->method('getTranslatedByMethod') | ||
->with($this->contentType, 'getName') | ||
->willReturn('Translated name'); | ||
|
||
$this->assertEquals('Translated name', $this->extension->getContentTypeName('content_type')); | ||
} | ||
|
||
public function testGetContentTypeNameWithContentTypeAsArgument() | ||
{ | ||
$this->contentTypeService->expects($this->never()) | ||
->method('loadContentType'); | ||
|
||
$this->translationHelper->expects($this->once()) | ||
->method('getTranslatedByMethod') | ||
->with($this->contentType, 'getName') | ||
->willReturn('Translated name'); | ||
|
||
$this->assertEquals('Translated name', $this->extension->getContentTypeName($this->contentType)); | ||
} | ||
} |
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 @@ | ||
coverage: | ||
status: | ||
patch: false | ||
changes: false | ||
project: | ||
default: | ||
target: auto | ||
comment: off |
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