12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /*
- * This file is part of the Sonata 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\Admin;
- use Sonata\AdminBundle\Admin\Admin;
- use Sonata\AdminBundle\Route\RouteCollection;
- use Sonata\AdminBundle\Model\ModelManagerInterface;
- class Admin_BaseAdminModelManagerTest extends Admin
- {
- }
- class BaseAdminModelManagerTest extends \PHPUnit_Framework_TestCase
- {
- public function testHook()
- {
- $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
- $modelManager->expects($this->once())->method('create');
- $modelManager->expects($this->once())->method('update');
- $modelManager->expects($this->once())->method('delete');
- $admin = new Admin_BaseAdminModelManagerTest('code', 'class', 'controller');
- $admin->setModelManager($modelManager);
- $t = new \stdClass();
- $admin->update($t);
- $admin->create($t);
- $admin->delete($t);
- }
- public function testObject()
- {
- $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
- $modelManager->expects($this->once())->method('find')->will($this->returnCallback(function($class, $id) {
- if ($class != 'class') {
- throw new \RuntimeException('Invalid class argument');
- }
- if ($id != 10) {
- throw new \RuntimeException('Invalid id argument');
- }
- }));
- $admin = new Admin_BaseAdminModelManagerTest('code', 'class', 'controller');
- $admin->setModelManager($modelManager);
- $admin->getObject(10);
- }
- public function testCreateQuery()
- {
- $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
- $modelManager->expects($this->once())->method('createQuery')->will($this->returnCallback(function($class) {
- if ($class != 'class') {
- throw new \RuntimeException('Invalid class argument');
- }
- }));
- $admin = new Admin_BaseAdminModelManagerTest('code', 'class', 'controller');
- $admin->setModelManager($modelManager);
- $admin->createQuery();
- }
- public function testId()
- {
- $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
- $modelManager->expects($this->exactly(2))->method('getNormalizedIdentifier');
- $admin = new Admin_BaseAdminModelManagerTest('code', 'class', 'controller');
- $admin->setModelManager($modelManager);
- $admin->id('Entity');
- $admin->getNormalizedIdentifier('Entity');
- }
- }
|