public function setUp() { date_default_timezone_set('Europe/London'); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->pool = new Pool($container, '', ''); $this->pool->setAdminServiceIds(array('sonata_admin_foo_service')); $this->pool->setAdminClasses(array('fooClass' => array('sonata_admin_foo_service'))); $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->xEditableTypeMapping = array('choice' => 'select', 'boolean' => 'select', 'text' => 'text', 'textarea' => 'textarea', 'html' => 'textarea', 'email' => 'email', 'string' => 'text', 'smallint' => 'text', 'bigint' => 'text', 'integer' => 'number', 'decimal' => 'number', 'currency' => 'number', 'percent' => 'number', 'url' => 'url'); $this->twigExtension = new SonataAdminExtension($this->pool, $this->logger); $this->twigExtension->setXEditableTypeMapping($this->xEditableTypeMapping); $loader = new StubFilesystemLoader(array(__DIR__ . '/../../../Resources/views/CRUD')); $this->environment = new \Twig_Environment($loader, array('strict_variables' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); $this->environment->addExtension($this->twigExtension); // translation extension $translator = new Translator('en', new MessageSelector()); $translator->addLoader('xlf', new XliffFileLoader()); $translator->addResource('xlf', __DIR__ . '/../../../Resources/translations/SonataAdminBundle.en.xliff', 'en', 'SonataAdminBundle'); $this->environment->addExtension(new TranslationExtension($translator)); // routing extension $xmlFileLoader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../../../Resources/config/routing'))); $routeCollection = $xmlFileLoader->load('sonata_admin.xml'); $xmlFileLoader = new XmlFileLoader(new FileLocator(array(__DIR__ . '/../../Fixtures/Resources/config/routing'))); $testRouteCollection = $xmlFileLoader->load('routing.xml'); $routeCollection->addCollection($testRouteCollection); $requestContext = new RequestContext(); $urlGenerator = new UrlGenerator($routeCollection, $requestContext); $this->environment->addExtension(new RoutingExtension($urlGenerator)); $this->environment->addExtension(new \Twig_Extensions_Extension_Text()); // initialize object $this->object = new \stdClass(); // initialize admin $this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); $this->admin->expects($this->any())->method('getCode')->will($this->returnValue('xyz')); $this->admin->expects($this->any())->method('id')->with($this->equalTo($this->object))->will($this->returnValue(12345)); $this->admin->expects($this->any())->method('getNormalizedIdentifier')->with($this->equalTo($this->object))->will($this->returnValue(12345)); $this->admin->expects($this->any())->method('trans')->will($this->returnCallback(function ($id, $parameters = array(), $domain = null) use($translator) { return $translator->trans($id, $parameters, $domain); })); $this->adminBar = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); $this->adminBar->expects($this->any())->method('isGranted')->will($this->returnValue(true)); $this->adminBar->expects($this->any())->method('getNormalizedIdentifier')->with($this->equalTo($this->object))->will($this->returnValue(12345)); // for php5.3 BC $admin = $this->admin; $adminBar = $this->adminBar; $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($admin, $adminBar) { if ($id == 'sonata_admin_foo_service') { return $admin; } elseif ($id == 'sonata_admin_bar_service') { return $adminBar; } return; })); // initialize field description $this->fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'); $this->fieldDescription->expects($this->any())->method('getName')->will($this->returnValue('fd_name')); $this->fieldDescription->expects($this->any())->method('getAdmin')->will($this->returnValue($this->admin)); $this->fieldDescription->expects($this->any())->method('getLabel')->will($this->returnValue('Data')); }