forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a21629c
commit ecddd93
Showing
1 changed file
with
76 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/* | ||
* This file is part of the Sonata project. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Route; | ||
|
||
use Sonata\AdminBundle\Route\RouteCollection; | ||
use Sonata\AdminBundle\Route\AdminPoolLoader; | ||
|
||
/** | ||
* @author Andrej Hudec <[email protected]> | ||
*/ | ||
class AdminPoolLoaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testSupports() | ||
{ | ||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); | ||
$pool = $this->getMock('Sonata\AdminBundle\Admin\Pool', array(), array($container, 'title', 'logoTitle')); | ||
|
||
$adminPoolLoader = new AdminPoolLoader($pool, array('foo_admin', 'bar_admin'), $container); | ||
|
||
$this->assertTrue($adminPoolLoader->supports('foo', 'sonata_admin')); | ||
$this->assertFalse($adminPoolLoader->supports('foo', 'bar')); | ||
} | ||
|
||
public function testLoad() | ||
{ | ||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); | ||
$pool = $this->getMock('Sonata\AdminBundle\Admin\Pool', array(), array($container, 'title', 'logoTitle')); | ||
|
||
$adminPoolLoader = new AdminPoolLoader($pool, array('foo_admin', 'bar_admin'), $container); | ||
|
||
$roureCollection1 = new RouteCollection('base.Code.Route.foo', 'baseRouteNameFoo', 'baseRoutePatternFoo', 'baseControllerNameFoo'); | ||
$roureCollection2 = new RouteCollection('base.Code.Route.bar', 'baseRouteNameBar', 'baseRoutePatternBar', 'baseControllerNameBar'); | ||
|
||
$roureCollection1->add('foo'); | ||
$roureCollection2->add('bar'); | ||
$roureCollection2->add('baz'); | ||
|
||
$admin1 = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface'); | ||
$admin1->expects($this->once()) | ||
->method('getRoutes') | ||
->will($this->returnValue($roureCollection1)); | ||
|
||
$admin2 = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface'); | ||
$admin2->expects($this->once()) | ||
->method('getRoutes') | ||
->will($this->returnValue($roureCollection2)); | ||
|
||
$pool->expects($this->any()) | ||
->method('getInstance') | ||
->will($this->returnCallback(function($id) use ($admin1, $admin2) { | ||
switch ($id) { | ||
case 'foo_admin': | ||
return $admin1; | ||
case 'bar_admin': | ||
return $admin2; | ||
} | ||
|
||
return null; | ||
})); | ||
|
||
$collection = $adminPoolLoader->load('foo', 'sonata_admin'); | ||
|
||
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection); | ||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('baseRouteNameFoo_foo')); | ||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('baseRouteNameBar_bar')); | ||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('baseRouteNameBar_bar')); | ||
} | ||
} |