コード例 #1
0
 public function setUp()
 {
     date_default_timezone_set('Europe/London');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->pool = new Pool($container, '', '');
     $this->twigExtension = new SonataAdminExtension($this->pool);
     $loader = new StubFilesystemLoader(array(__DIR__ . '/../../../Resources/views/CRUD'));
     $this->environment = new \Twig_Environment($loader, array('strict_variables' => true, 'cache' => false, 'autoescape' => true, '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->twigExtension->initRuntime($this->environment);
     // initialize object
     $this->object = new \stdClass();
     // initialize admin
     $this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $this->admin->expects($this->any())->method('isGranted')->will($this->returnValue(true));
     $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) {
         return $id;
     }));
     // for php5.3 BC
     $admin = $this->admin;
     $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($admin) {
         if ($id == 'sonata_admin_foo_service') {
             return $admin;
         }
         return null;
     }));
     // 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'));
 }