本文整理汇总了PHP中Sonata\AdminBundle\Admin\Pool::setAdminServiceIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::setAdminServiceIds方法的具体用法?PHP Pool::setAdminServiceIds怎么用?PHP Pool::setAdminServiceIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\Pool
的用法示例。
在下文中一共展示了Pool::setAdminServiceIds方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
if (!interface_exists('JMS\\TranslationBundle\\Translation\\ExtractorInterface')) {
$this->markTestSkipped('JMS Translator Bundle does not exist');
}
$this->fooAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$this->barAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
// php 5.3 BC
$fooAdmin = $this->fooAdmin;
$barAdmin = $this->barAdmin;
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($fooAdmin, $barAdmin) {
switch ($id) {
case 'foo_admin':
return $fooAdmin;
case 'bar_admin':
return $barAdmin;
}
return null;
}));
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
$this->pool = new Pool($container, '', '');
$this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin'));
$this->adminExtractor = new AdminExtractor($this->pool, $logger);
$this->adminExtractor->setLogger($logger);
}
示例2: testConfigureWithException2
public function testConfigureWithException2()
{
$this->setExpectedException('RuntimeException', 'Unable to find the admin class related to the current controller ' . '(Sonata\\AdminBundle\\Controller\\CRUDController)');
$this->pool->setAdminServiceIds(array('nonexistent.admin'));
$this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
$this->protectedTestedMethods['configure']->invoke($this->controller);
}
示例3: testExecuteWithException2
public function testExecuteWithException2()
{
$application = new Application();
$command = new SetupAclCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo'));
return $pool;
case 'sonata.admin.manipulator.acl.admin':
return new \stdClass();
case 'acme.admin.foo':
return $admin;
}
return;
}));
$command->setContainer($container);
$application->add($command);
$command = $application->find('sonata:admin:setup-acl');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('@Starting ACL AdminBundle configuration\\s+The interface "AdminAclManipulatorInterface" is not implemented for stdClass: ignoring@', $commandTester->getDisplay());
}
示例4: testExecute
public function testExecute()
{
$application = new Application();
$command = new ListAdminCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$admin1 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin1->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Foo'));
$admin2 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin2->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Bar'));
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin1, $admin2) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo', 'acme.admin.bar'));
return $pool;
break;
case 'acme.admin.foo':
return $admin1;
break;
case 'acme.admin.bar':
return $admin2;
break;
}
return null;
}));
$command->setContainer($container);
$application->add($command);
$command = $application->find('sonata:admin:list');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('@Admin services:\\s+acme.admin.foo\\s+Acme\\\\Entity\\\\Foo\\s+acme.admin.bar\\s+Acme\\\\Entity\\\\Bar@', $commandTester->getDisplay());
}
示例5: setUp
protected function setUp()
{
$this->application = new Application();
$command = new ExplainAdminCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo'));
$this->admin->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Foo'));
$this->admin->expects($this->any())->method('getBaseControllerName')->will($this->returnValue('SonataAdminBundle:CRUD'));
$routeCollection = new RouteCollection('foo', 'fooBar', 'foo-bar', 'SonataAdminBundle:CRUD');
$routeCollection->add('list');
$routeCollection->add('edit');
$this->admin->expects($this->any())->method('getRoutes')->will($this->returnValue($routeCollection));
$fieldDescription1 = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription1->expects($this->any())->method('getType')->will($this->returnValue('text'));
$fieldDescription1->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:foo_text.html.twig'));
$fieldDescription2 = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription2->expects($this->any())->method('getType')->will($this->returnValue('datetime'));
$fieldDescription2->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:bar_datetime.html.twig'));
$this->admin->expects($this->any())->method('getListFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('getFilterFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('getFormTheme')->will($this->returnValue(array('FooBundle::bar.html.twig')));
$this->admin->expects($this->any())->method('getFormFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('isChild')->will($this->returnValue(true));
// php 5.3 BC
$adminParent = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$adminParent->expects($this->any())->method('getCode')->will($this->returnValue('foo_child'));
$this->admin->expects($this->any())->method('getParent')->will($this->returnCallback(function () use($adminParent) {
return $adminParent;
}));
// Prefer Symfony 2.x interfaces
if (interface_exists('Symfony\\Component\\Validator\\MetadataFactoryInterface')) {
$this->validatorFactory = $this->getMock('Symfony\\Component\\Validator\\MetadataFactoryInterface');
$validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
$validator->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($this->validatorFactory));
} else {
$this->validatorFactory = $this->getMock('Symfony\\Component\\Validator\\Mapping\\Factory\\MetadataFactoryInterface');
$validator = $this->getMock('Symfony\\Component\\Validator\\Validator\\ValidatorInterface');
$validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($this->validatorFactory));
}
// php 5.3 BC
$admin = $this->admin;
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin, $validator) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo', 'acme.admin.bar'));
return $pool;
case 'validator':
return $validator;
case 'acme.admin.foo':
return $admin;
}
return;
}));
$command->setContainer($container);
$this->application->add($command);
}
示例6: testGetUrlsafeIdentifier
public function testGetUrlsafeIdentifier()
{
$entity = new \stdClass();
// set admin to pool
$this->pool->setAdminServiceIds(array('sonata_admin_foo_service'));
$this->pool->setAdminClasses(array('stdClass' => array('sonata_admin_foo_service')));
$this->admin->expects($this->once())->method('getUrlsafeIdentifier')->with($this->equalTo($entity))->will($this->returnValue(1234567));
$this->assertEquals(1234567, $this->twigExtension->getUrlsafeIdentifier($entity));
}
示例7: testGetDashboardGroups
public function testGetDashboardGroups()
{
$admin_group1 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin_group1->expects($this->once())->method('showIn')->will($this->returnValue(true));
$admin_group2 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin_group2->expects($this->once())->method('showIn')->will($this->returnValue(false));
$admin_group3 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin_group3->expects($this->once())->method('showIn')->will($this->returnValue(false));
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($this->any())->method('get')->will($this->onConsecutiveCalls($admin_group1, $admin_group2, $admin_group3));
$pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png');
$pool->setAdminServiceIds(array('sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'));
$pool->setAdminGroups(array('adminGroup1' => array('items' => array('itemKey' => 'sonata.user.admin.group1')), 'adminGroup2' => array('items' => array('itemKey' => 'sonata.user.admin.group2')), 'adminGroup3' => array('items' => array('itemKey' => 'sonata.user.admin.group3'))));
$groups = $pool->getDashboardGroups();
$this->assertCount(1, $groups);
}
示例8: testSetObjectFieldValueActionWithViolations
public function testSetObjectFieldValueActionWithViolations()
{
$bar = new AdminControllerHelper_Bar();
$object = new AdminControllerHelper_Foo();
$object->setBar($bar);
$fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getOption')->will($this->returnValue(true));
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin->expects($this->once())->method('getObject')->will($this->returnValue($object));
$admin->expects($this->once())->method('isGranted')->will($this->returnValue(true));
$admin->expects($this->once())->method('getListFieldDescription')->will($this->returnValue($fieldDescription));
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($this->any())->method('get')->will($this->returnValue($admin));
$twig = new Twig();
$request = new Request(array('code' => 'sonata.post.admin', 'objectId' => 42, 'field' => 'bar.enabled', 'value' => 1, 'context' => 'list'), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'));
$pool = new Pool($container, 'title', 'logo');
$pool->setAdminServiceIds(array('sonata.post.admin'));
$helper = new AdminHelper($pool);
$violations = new ConstraintViolationList(array(new ConstraintViolation('error1', null, array(), null, 'enabled', null), new ConstraintViolation('error2', null, array(), null, 'enabled', null)));
$validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
$validator->expects($this->once())->method('validateProperty')->with($bar, 'enabled')->will($this->returnValue($violations));
$controller = new HelperController($twig, $pool, $helper, $validator);
$response = $controller->setObjectFieldValueAction($request);
$this->assertEquals('{"status":"KO","message":"error1\\nerror2"}', $response->getContent());
}
示例9: testGetAdminServiceIds
public function testGetAdminServiceIds()
{
$this->pool->setAdminServiceIds(array('sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'));
$this->assertEquals(array('sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'), $this->pool->getAdminServiceIds());
}
示例10: setUp
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->categoryAdminController = new CategoryAdminController();
$this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$this->categoryManager = $this->getMockBuilder('Sonata\\ClassificationBundle\\Entity\\CategoryManager')->disableOriginalConstructor()->getMock();
$categoryManager = $this->categoryManager;
$this->contextManager = $this->getMockBuilder('Sonata\\ClassificationBundle\\Entity\\ContextManager')->disableOriginalConstructor()->getMock();
$contextManager = $this->contextManager;
$this->view = $this->getMock('Symfony\\Component\\Form\\FormView');
$this->form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
$this->form->expects($this->any())->method('createView')->will($this->returnValue($this->view));
$this->dataGrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface');
$this->dataGrid->expects($this->any())->method('getForm')->will($this->returnValue($this->form));
$this->request = new Request();
$this->pool = new Pool($this->container, 'title', 'logo.png');
$this->pool->setAdminServiceIds(array('foo.admin'));
$this->request->attributes->set('_sonata_admin', 'foo.admin');
$this->admin = $this->getMockBuilder('Sonata\\ClassificationBundle\\Admin\\CategoryAdmin')->disableOriginalConstructor()->getMock();
$this->admin->expects($this->any())->method('getPersistentParameter')->will($this->returnValue('persistentParameter'));
$this->admin->expects($this->any())->method('getDataGrid')->will($this->returnValue($this->dataGrid));
$params = array();
$template = '';
$templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\DelegatingEngine', array(), array($this->container, array()));
$templating->expects($this->any())->method('renderResponse')->will($this->returnCallback(function ($view, array $parameters = array(), Response $response = null) use(&$params, &$template) {
$template = $view;
if (null === $response) {
$response = new Response();
}
$params = $parameters;
return $response;
}));
$twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
$twigRenderer = $this->getMock('Symfony\\Bridge\\Twig\\Form\\TwigRendererInterface');
$formExtension = new FormExtension($twigRenderer);
$twig->expects($this->any())->method('getExtension')->will($this->returnCallback(function ($name) use($formExtension) {
switch ($name) {
case 'form':
return $formExtension;
}
return;
}));
$this->csrfProvider = $this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface');
$this->csrfProvider->expects($this->any())->method('generateCsrfToken')->will($this->returnCallback(function ($intention) {
return 'csrf-token-123_' . $intention;
}));
$this->csrfProvider->expects($this->any())->method('isCsrfTokenValid')->will($this->returnCallback(function ($intention, $token) {
if ($token == 'csrf-token-123_' . $intention) {
return true;
}
return false;
}));
// php 5.3 BC
$pool = $this->pool;
$admin = $this->admin;
$request = $this->request;
$csrfProvider = $this->csrfProvider;
$requestStack = null;
if (Kernel::MINOR_VERSION > 3) {
$requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
$requestStack->push($request);
}
$this->container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($pool, $admin, $request, $requestStack, $templating, $twig, $csrfProvider, $categoryManager, $contextManager) {
switch ($id) {
case 'sonata.admin.pool':
return $pool;
case 'foo.admin':
return $admin;
case 'request':
return $request;
case 'request_stack':
return $requestStack;
case 'templating':
return $templating;
case 'twig':
return $twig;
case 'form.csrf_provider':
return $csrfProvider;
case 'sonata.classification.manager.category':
return $categoryManager;
case 'sonata.classification.manager.context':
return $contextManager;
}
return;
}));
$this->categoryAdminController->setContainer($this->container);
}