123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- /*
- * This file is part of the Sonata Project package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\AdminBundle\Tests\Command;
- use Sonata\AdminBundle\Command\Validators;
- /**
- * @author Andrej Hudec <pulzarraider@gmail.com>
- */
- class ValidatorsTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @dataProvider getValidateUsernameTests
- */
- public function testValidateUsername($expected, $value)
- {
- $this->assertSame($expected, Validators::validateUsername($value));
- }
- public function getValidateUsernameTests()
- {
- return array(
- array('Foo', 'Foo'),
- array('abcdefghijklmnopqrstuvwxyz.ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789', 'abcdefghijklmnopqrstuvwxyz.ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'),
- );
- }
- /**
- * @dataProvider getValidateUsernameWithExceptionTests
- */
- public function testValidateUsernameWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateUsername($value);
- }
- public function getValidateUsernameWithExceptionTests()
- {
- return array(
- array(null),
- );
- }
- /**
- * @dataProvider getValidateEntityNameTests
- */
- public function testValidateEntityName($expected, $value)
- {
- $this->assertSame($expected, Validators::validateEntityName($value));
- }
- public function getValidateEntityNameTests()
- {
- return array(
- array(array('AcmeBlogBundle', 'Post'), 'AcmeBlogBundle:Post'),
- array(array('Foo\Bar\BlogBundle', 'Post'), 'Foo/Bar/BlogBundle:Post'),
- array(array('Foo\Bar\BlogBundle', 'Post'), 'Foo\Bar\BlogBundle:Post'),
- );
- }
- /**
- * @dataProvider getValidateEntityNamesWithExceptionTests
- */
- public function testValidateEntityNameWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateEntityName($value);
- }
- public function getValidateEntityNamesWithExceptionTests()
- {
- return array(
- array('Sonata\AdminBundle\Admin\AbstractAdmin'),
- array('Sonata/AdminBundle/Admin/Admin'),
- array('Foo/Bar/Controller'),
- array('Foo/BarController'),
- array('Foo_Bar'),
- array('FooBarController'),
- array('FooBarAdmin'),
- );
- }
- /**
- * @dataProvider getValidateClassTests
- */
- public function testValidateClass($expected, $value)
- {
- $this->assertSame($expected, Validators::validateClass($value));
- }
- public function getValidateClassTests()
- {
- return array(
- array('Sonata\AdminBundle\Admin\AbstractAdmin', 'Sonata\AdminBundle\Admin\AbstractAdmin'),
- array('Sonata\AdminBundle\Admin\AbstractAdmin', 'Sonata/AdminBundle/Admin/AbstractAdmin'),
- );
- }
- /**
- * @dataProvider getValidateClassWithExceptionTests
- */
- public function testValidateClassWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateClass($value);
- }
- public function getValidateClassWithExceptionTests()
- {
- return array(
- array('Foo:BarAdmin'),
- array('Foo:Bar:Admin'),
- array('Foo/Bar/Admin'),
- );
- }
- /**
- * @dataProvider getValidateAdminClassBasenameTests
- */
- public function testValidateAdminClassBasename($expected, $value)
- {
- $this->assertSame($expected, Validators::validateAdminClassBasename($value));
- }
- public function getValidateAdminClassBasenameTests()
- {
- return array(
- array('FooBarAdmin', 'FooBarAdmin'),
- array('Foo\Foo\BarAdmin', 'Foo\Foo\BarAdmin'),
- array('Foo\Foo\BarAdmin', 'Foo/Foo/BarAdmin'),
- );
- }
- /**
- * @dataProvider getValidateAdminClassBasenameWithExceptionTests
- */
- public function testValidateAdminClassBasenameWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateAdminClassBasename($value);
- }
- public function getValidateAdminClassBasenameWithExceptionTests()
- {
- return array(
- array('Foo:BarAdmin'),
- array('Foo:Bar:Admin'),
- array('*+-!:@&^%'),
- );
- }
- /**
- * @dataProvider getValidateControllerClassBasenameTests
- */
- public function testValidateControllerClassBasename($expected, $value)
- {
- $this->assertSame($expected, Validators::validateControllerClassBasename($value));
- }
- public function getValidateControllerClassBasenameTests()
- {
- return array(
- array('FooBarController', 'FooBarController'),
- array('Foo\Foo\BarController', 'Foo/Foo/BarController'),
- array('Foo\Foo\BarController', 'Foo\Foo\BarController'),
- );
- }
- /**
- * @dataProvider getValidateControllerClassBasenameWithExceptionTests
- */
- public function testValidateControllerClassBasenameWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateControllerClassBasename($value);
- }
- public function getValidateControllerClassBasenameWithExceptionTests()
- {
- return array(
- array(' foobar '),
- array(' FooBar'),
- array('Foo Bar'),
- array('Foo-Bar'),
- array('foo*'),
- array('foo+'),
- array('foo-'),
- array('foo!'),
- array('foo@'),
- array('foo&'),
- array('foo%'),
- array('foo^'),
- array('foo(bar)'),
- array('foo[bar]'),
- array('foo{bar}'),
- array('Foo/Bar'),
- array('Foo\Bar'),
- array('Foo/BarControllr'),
- array('Foo\BarControllr'),
- array('Foo:BarControllr'),
- );
- }
- /**
- * @dataProvider getValidateServicesFileTests
- */
- public function testValidateServicesFile($expected, $value)
- {
- $this->assertSame($expected, Validators::validateServicesFile($value));
- }
- public function getValidateServicesFileTests()
- {
- return array(
- array('foobar', 'foobar'),
- array('fooBar', 'fooBar'),
- array(' foo Bar ', ' foo Bar '),
- array('Foo/Bar', '/Foo/Bar/'),
- array('Foo/BAR', '/Foo/BAR/'),
- array('Foo/Bar', '/Foo/Bar'),
- array('Foo/Bar', 'Foo/Bar/'),
- );
- }
- /**
- * @dataProvider getValidateServiceIdTests
- */
- public function testValidateServiceId($value)
- {
- $this->assertSame($value, Validators::validateServiceId($value));
- }
- public function getValidateServiceIdTests()
- {
- return array(
- array('abcdefghijklmnopqrstuvwxyz.ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'),
- array('Foo_Bar_0123'),
- array('Foo.Bar.0123'),
- );
- }
- /**
- * @dataProvider getValidateServiceIdWithExceptionTests
- */
- public function testValidateServiceIdWithException($value)
- {
- $this->setExpectedException('\InvalidArgumentException');
- Validators::validateServiceId($value);
- }
- public function getValidateServiceIdWithExceptionTests()
- {
- return array(
- array(' foobar '),
- array(' FooBar'),
- array('Foo Bar'),
- array('Foo-Bar'),
- array('foo*'),
- array('foo+'),
- array('foo-'),
- array('foo!'),
- array('foo@'),
- array('foo&'),
- array('foo%'),
- array('foo^'),
- array('foo:'),
- array('foo(bar)'),
- array('foo[bar]'),
- array('foo{bar}'),
- array('Foo/Bar'),
- array('Foo\Bar'),
- );
- }
- }
|