Skip to content

Commit

Permalink
Added AdminPoolLoaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Sep 26, 2013
1 parent a21629c commit ecddd93
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Tests/Route/AdminPoolLoaderTest.php
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'));
}
}

0 comments on commit ecddd93

Please sign in to comment.