Skip to content

Commit

Permalink
added content extension test with exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Martynas Sudintas committed Nov 3, 2014
1 parent 50e003a commit 285abd1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class ContentExtensionsIntegrationTest extends ElasticsearchTestCase
class ContentExtensionsTest extends ElasticsearchTestCase
{
/**
* {@inheritdoc}
Expand All @@ -39,11 +39,11 @@ protected function getDataArray()
}

/**
* Test data provider for testSnippetFunctionIntegration().
* Test data provider for testSnippetFunction().
*
* @return array
*/
public function getTestSnippetFunctionIntegrationData()
public function getTestSnippetFunctionData()
{
$out = array();

Expand Down Expand Up @@ -78,9 +78,9 @@ public function getTestSnippetFunctionIntegrationData()
* @param string $expectedContent
* @param string $strategy
*
* @dataProvider getTestSnippetFunctionIntegrationData()
* @dataProvider getTestSnippetFunctionData()
*/
public function testSnippetFunctionIntegration($request, $slug, $expectedContent, $strategy = 'esi')
public function testSnippetFunction($request, $slug, $expectedContent, $strategy = 'esi')
{
// Custom logic for Symfony 2.4+.
if ($this->getContainer()->has('request_stack')) {
Expand Down
51 changes: 47 additions & 4 deletions Tests/Unit/Twig/ContentExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testGetContentsBySlugsFunction()

$extension = $this->getContentExtension([$document2, $document]);

$this->assertEquals(array($document, $document2), $extension->getContentsBySlugsFunction(array(1, 2), true));
$this->assertEquals([$document, $document2], $extension->getContentsBySlugsFunction([1, 2], true));
}

/**
Expand All @@ -80,13 +80,13 @@ public function getTestSnippetFunctionData()
$out = array();

// Case #0: inline strategy.
$out[] = array('inline');
$out[] = ['inline'];

// Case #1: esi strategy.
$out[] = array('esi');
$out[] = ['esi'];

// Case #2: ssi strategy.
$out[] = array('ssi');
$out[] = ['ssi'];

return $out;
}
Expand Down Expand Up @@ -127,6 +127,49 @@ public function testSnippetFunction($strategy)
$extension->snippetFunction(1);
}

/**
* Tests extension when exception is thrown.
*/
public function testSnippetFunctionWithException()
{
$router = $this->getRouterMock();
$router
->expects($this->once())
->method('generate')
->with(
'_ongr_plain_cms_snippet',
[
'template' => null,
'slug' => 1
]
);

$fragmentHandlerMock = $this->getFragmentHandlerMock();
$fragmentHandlerMock
->expects($this->at(0))
->method('render')
->with(
$this->anything(),
[]
)->will($this->throwException(new \InvalidArgumentException()));
$fragmentHandlerMock
->expects($this->at(1))
->method('render')
->with(
$this->anything()
)->will($this->returnValue('content'));

$extension = new ContentExtension(
$fragmentHandlerMock,
$router,
[],
$this->getManager(),
'AcmeTestBundle:Content'
);

$this->assertEquals('content', $extension->snippetFunction(1));
}

/**
* @param array $results
*
Expand Down

0 comments on commit 285abd1

Please sign in to comment.