mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Bundle - getBundleViewPath() method - verify name of bundle
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
namespace Meritoo\Common\Test\Utilities;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Bundle;
|
||||
|
||||
@@ -29,6 +30,7 @@ class BundleTest extends BaseTestCase
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideEmptyViewPathAndBundle
|
||||
*/
|
||||
public function testGetBundleViewPathUsingEmptyPathAndBundle($viewPath, $bundleName)
|
||||
@@ -36,11 +38,30 @@ class BundleTest extends BaseTestCase
|
||||
self::assertNull(Bundle::getBundleViewPath($viewPath, $bundleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndIncorrectBundleName
|
||||
*/
|
||||
public function testGetBundleViewPathUsingIncorrectBundleName($viewPath, $bundleName)
|
||||
{
|
||||
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
|
||||
. ' there everything ok?';
|
||||
|
||||
$message = sprintf($template, $bundleName);
|
||||
$this->setExpectedException(IncorrectBundleNameException::class, $message);
|
||||
|
||||
Bundle::getBundleViewPath($viewPath, $bundleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $expected Expected path to view / template
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundle
|
||||
*/
|
||||
public function testGetBundleViewPathUsingDefaultExtension($viewPath, $bundleName, $expected)
|
||||
@@ -54,6 +75,7 @@ class BundleTest extends BaseTestCase
|
||||
* @param string $extension (optional) Extension of the view / template
|
||||
* @param string $expected Expected path to view / template
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundleAndExtension
|
||||
*/
|
||||
public function testGetBundleViewPathUsingCustomExtension($viewPath, $bundleName, $extension, $expected)
|
||||
@@ -84,6 +106,29 @@ class BundleTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and incorrect name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndIncorrectBundleName()
|
||||
{
|
||||
yield[
|
||||
'User:Active',
|
||||
'myExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and name of bundle
|
||||
*
|
||||
@@ -92,15 +137,21 @@ class BundleTest extends BaseTestCase
|
||||
public function provideViewPathAndBundle()
|
||||
{
|
||||
yield[
|
||||
'Ipsum',
|
||||
'Lorem',
|
||||
'Lorem:Ipsum.html.twig',
|
||||
':User',
|
||||
'MyExtraBundle',
|
||||
'MyExtraBundle::User.html.twig',
|
||||
];
|
||||
|
||||
yield[
|
||||
'FusceElementum',
|
||||
'LobortisTincidunt',
|
||||
'LobortisTincidunt:FusceElementum.html.twig',
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'MyExtraBundle:User:Active.html.twig',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeousBundle',
|
||||
'MySuperExtraGorgeousBundle:User:Active.html.twig',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -112,17 +163,17 @@ class BundleTest extends BaseTestCase
|
||||
public function provideViewPathAndBundleAndExtension()
|
||||
{
|
||||
yield[
|
||||
'Ipsum',
|
||||
'Lorem',
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Ipsum',
|
||||
'Lorem',
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'js.twig',
|
||||
'Lorem:Ipsum.js.twig',
|
||||
'MyExtraBundle:User:Active.js.twig',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user