diff --git a/src/Resources/views/includes/_include_embedded_list.html.twig b/src/Resources/views/includes/_include_embedded_list.html.twig
index 4e66cae1..3838b3d9 100644
--- a/src/Resources/views/includes/_include_embedded_list.html.twig
+++ b/src/Resources/views/includes/_include_embedded_list.html.twig
@@ -1,4 +1,5 @@
-{% set action_params = { entity: entity, action: 'embeddedList', ext_filters: ext_filters, 'hidden-fields': hidden_fields } %}
+{% set action_params = { (object_type): object, action: 'embeddedList', ext_filters: ext_filters, 'hidden-fields': hidden_fields } %}
+
{% if sort is not null %}
{% set action_params = action_params|merge({ sortField: sort.field, sortDirection: sort.direction}) %}
{% endif %}
@@ -6,4 +7,4 @@
{% set action_params = action_params|merge({ 'max-results': max_results}) %}
{% endif %}
-{{ render(path('easyadmin', action_params)) }}
+{{ render(easyadmin_path_from_request_parameters(action_params)) }}
diff --git a/src/Router/MongoOdmEasyAdminRouter.php b/src/Router/MongoOdmEasyAdminRouter.php
new file mode 100644
index 00000000..99bd5f23
--- /dev/null
+++ b/src/Router/MongoOdmEasyAdminRouter.php
@@ -0,0 +1,101 @@
+configManager = $configManager;
+ $this->urlGenerator = $urlGenerator;
+ $this->propertyAccessor = $propertyAccessor;
+ $this->requestStack = $requestStack;
+ }
+
+ /**
+ * @param object|string $document
+ * @param string $action
+ * @param array $parameters
+ *
+ * @throws UndefinedDocumentException
+ *
+ * @return string
+ */
+ public function generate($document, $action, array $parameters = [])
+ {
+ if (\is_object($document)) {
+ $config = $this->getDocumentConfigByClass(\get_class($document));
+
+ // casting to string is needed because entities can use objects as primary keys
+ $parameters['id'] = (string) $this->propertyAccessor->getValue($document, 'id');
+ } else {
+ $config = class_exists($document)
+ ? $this->getDocumentConfigByClass($document)
+ : $this->configManager->getDocumentConfig($document);
+ }
+
+ $parameters['document'] = $config['name'];
+ $parameters['action'] = $action;
+
+ $referer = $parameters['referer'] ?? null;
+
+ $request = null;
+ if (null !== $this->requestStack) {
+ $request = $this->requestStack->getCurrentRequest();
+ }
+
+ if (false === $referer) {
+ unset($parameters['referer']);
+ } elseif (
+ $request
+ && !\is_string($referer)
+ && (true === $referer || \in_array($action, ['new', 'edit', 'delete'], true))
+ ) {
+ $parameters['referer'] = urlencode($request->getUri());
+ }
+
+ return $this->urlGenerator->generate('easyadmin_mongo_odm', $parameters);
+ }
+
+ /**
+ * @param string $class
+ *
+ * @throws UndefinedDocumentException
+ *
+ * @return array
+ */
+ private function getDocumentConfigByClass($class)
+ {
+ if (!$config = $this->configManager->getDocumentConfigByClass($this->getRealClass($class))) {
+ throw new UndefinedDocumentException(['document_name' => $class]);
+ }
+
+ return $config;
+ }
+
+ /**
+ * @param string $class
+ *
+ * @return string
+ */
+ private function getRealClass($class)
+ {
+ if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
+ return $class;
+ }
+
+ return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
+ }
+}
diff --git a/src/Security/AdminAuthorizationChecker.php b/src/Security/AdminAuthorizationChecker.php
index 2f19ea32..8ac2e894 100644
--- a/src/Security/AdminAuthorizationChecker.php
+++ b/src/Security/AdminAuthorizationChecker.php
@@ -17,20 +17,20 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker,
}
/**
- * Throws an error if user has no access to the entity action.
+ * Throws an error if user has no access to the object action.
*
* @param mixed $subject
*/
- public function checksUserAccess(array $entityConfig, string $actionName, $subject = null)
+ public function checksUserAccess(array $objectConfig, string $actionName, $subject = null)
{
if ($this->adminMinimumRole && !$this->authorizationChecker->isGranted($this->adminMinimumRole)) {
throw new AccessDeniedException(\sprintf('You must be granted one of following role(s) [%s] to access admin !', \is_array($this->adminMinimumRole) ? \implode('|', $this->adminMinimumRole) : $this->adminMinimumRole));
}
- $requiredRole = $this->getRequiredRole($entityConfig, $actionName);
+ $requiredRole = $this->getRequiredRole($objectConfig, $actionName);
if ($requiredRole && !$this->authorizationChecker->isGranted($requiredRole, $subject)) {
- throw new AccessDeniedException(\sprintf('You must be granted one of following role(s) [%s] to perform this entity action !', \is_array($requiredRole) ? \implode('|', $requiredRole) : $requiredRole));
+ throw new AccessDeniedException(\sprintf('You must be granted one of following role(s) [%s] to perform this object action !', \is_array($requiredRole) ? \implode('|', $requiredRole) : $requiredRole));
}
}
@@ -41,10 +41,10 @@ public function checksUserAccess(array $entityConfig, string $actionName, $subje
*
* @return bool
*/
- public function isEasyAdminGranted(array $entityConfig, string $actionName, $subject = null)
+ public function isEasyAdminGranted(array $objectConfig, string $actionName, $subject = null)
{
try {
- $this->checksUserAccess($entityConfig, $actionName, $subject);
+ $this->checksUserAccess($objectConfig, $actionName, $subject);
} catch (AccessDeniedException $e) {
return false;
}
@@ -52,17 +52,17 @@ public function isEasyAdminGranted(array $entityConfig, string $actionName, $sub
return true;
}
- protected function getRequiredRole(array $entityConfig, string $actionName)
+ protected function getRequiredRole(array $objectConfig, string $actionName)
{
// Prevent from security breach: role for 'list' action was not required for 'List' nor 'LIST'...
$actionName = \strtolower($actionName);
- if (isset($entityConfig[$actionName]) && isset($entityConfig[$actionName]['role'])) {
- return $entityConfig[$actionName]['role'];
- } elseif (isset($entityConfig['role_prefix'])) {
- return $entityConfig['role_prefix'].'_'.\strtoupper($actionName);
+ if (isset($objectConfig[$actionName]) && isset($objectConfig[$actionName]['role'])) {
+ return $objectConfig[$actionName]['role'];
+ } elseif (isset($objectConfig['role_prefix'])) {
+ return $objectConfig['role_prefix'].'_'.\strtoupper($actionName);
}
- return $entityConfig['role'] ?? null;
+ return $objectConfig['role'] ?? null;
}
}
diff --git a/src/Twig/AdminAuthorizationExtension.php b/src/Twig/AdminAuthorizationExtension.php
index fedfda64..6b7e8b76 100644
--- a/src/Twig/AdminAuthorizationExtension.php
+++ b/src/Twig/AdminAuthorizationExtension.php
@@ -32,17 +32,18 @@ public function getFunctions(): array
];
}
- public function isEasyAdminGranted(array $entityConfig, string $actionName = 'list', $subject = null)
+ public function isEasyAdminGranted(array $objectConfig, string $actionName = 'list', $subject = null)
{
- return $this->adminAuthorizationChecker->isEasyAdminGranted($entityConfig, $actionName, $subject);
+ return $this->adminAuthorizationChecker->isEasyAdminGranted($objectConfig, $actionName, $subject);
}
public function pruneItemsActions(
- array $itemActions, array $entityConfig, array $forbiddenActions = [], $subject = null
+ array $itemActions, array $objectConfig, array $forbiddenActions = [], $subject = null
) {
- return \array_filter($itemActions, function ($action) use ($entityConfig, $forbiddenActions, $subject) {
+ return \array_filter($itemActions, function ($action) use ($objectConfig, $forbiddenActions, $subject) {
return !\in_array($action, $forbiddenActions)
- && $this->isEasyAdminGranted($entityConfig, $action, $subject);
+ && $this->isEasyAdminGranted($objectConfig, $action, $subject)
+ ;
}, ARRAY_FILTER_USE_KEY);
}
}
diff --git a/src/Twig/EasyAdminExtensionTwigExtension.php b/src/Twig/EasyAdminExtensionTwigExtension.php
new file mode 100644
index 00000000..a0ca2337
--- /dev/null
+++ b/src/Twig/EasyAdminExtensionTwigExtension.php
@@ -0,0 +1,195 @@
+easyAdminRouter = $easyAdminRouter;
+ $this->mongoOdmEasyAdminRouter = $mongoOdmEasyAdminRouter;
+ $this->entityConfigManager = $entityConfigManager;
+ $this->mongoOdmConfigManager = $mongoOdmConfigManager;
+ $this->router = $router;
+ }
+
+ public function getFunctions()
+ {
+ return [
+ new TwigFunction('easyadmin_object', [$this, 'getObjectConfiguration']),
+ new TwigFunction('easyadmin_object_type', [$this, 'getObjectType']),
+ new TwigFunction('easyadmin_path', [$this, 'getEasyAdminPath']),
+ new TwigFunction('easyadmin_path_from_request_parameters', [$this, 'getEasyAdminPathFromRequestParameters']),
+ new TwigFunction('easyadmin_object_twig_path', [$this, 'getTwigPath']),
+ new TwigFunction('easyadmin_object_base_twig_path', [$this, 'getBaseTwigPath']),
+ new TwigFunction('easyadmin_object_get_actions_for_*_item', [$this, 'getActionsForItem'], ['needs_environment' => true]),
+ new TwigFunction('easyadmin_object_render_field_for_*_view', [$this, 'renderObjectField'], ['is_safe' => ['html'], 'needs_environment' => true]),
+ ];
+ }
+
+ public function getActionsForItem(
+ Environment $twig, string $view, string $objectType, string $objectName
+ ) {
+ if ('document' === $objectType && $twig->getFunction('easyadmin_mongo_odm_get_actions_for_*_item')) {
+ $function = $twig->getFunction('easyadmin_mongo_odm_get_actions_for_*_item');
+ } else {
+ $function = $twig->getFunction('easyadmin_get_actions_for_*_item');
+ }
+
+ return \call_user_func($function->getCallable(), $view, $objectName);
+ }
+
+ public function renderObjectField(
+ Environment $twig, string $view, string $objectType, string $objectName, $item, array $fieldMetadata
+ ) {
+ if ('document' === $objectType && $twig->getFunction('easyadmin_mongo_odm_render_field_for_*_view')) {
+ $function = $twig->getFunction('easyadmin_mongo_odm_render_field_for_*_view');
+ } else {
+ $function = $twig->getFunction('easyadmin_render_field_for_*_view');
+ }
+
+ return \call_user_func($function->getCallable(), $twig, $view, $objectName, $item, $fieldMetadata);
+ }
+
+ /**
+ * Returns the namespaced Twig path.
+ *
+ * @param Request $request
+ * @param string $path
+ *
+ * @return string
+ */
+ public function getTwigPath(Request $request, string $path)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return \sprintf('@EasyAdmin/%s', $path);
+ } elseif ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return \sprintf('@EasyAdminMongoOdm/%s', $path);
+ }
+
+ // Fallback not entity/document admin pages based on EasyAdmin layout ?
+ return \sprintf('@EasyAdmin/%s', $path);
+ }
+
+ /**
+ * Returns the namespaced base Twig path.
+ *
+ * @param Request $request
+ * @param string $path
+ *
+ * @return string
+ */
+ public function getBaseTwigPath(Request $request, string $path)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return \sprintf('@!EasyAdmin/%s', $path);
+ } elseif ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return \sprintf('@!EasyAdminMongoOdm/%s', $path);
+ }
+
+ // Fallback not entity/document admin pages based on EasyAdmin layout ?
+ return \sprintf('@!EasyAdmin/%s', $path);
+ }
+
+ /**
+ * Returns the entire configuration of the given object.
+ *
+ * @param Request $request
+ *
+ * @return array|null
+ */
+ public function getObjectConfiguration(Request $request)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return $this->entityConfigManager->getEntityConfig($request->query->get('entity'));
+ }
+
+ if (null === $this->mongoOdmConfigManager) {
+ return null;
+ }
+
+ if ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return $this->mongoOdmConfigManager->getDocumentConfig($request->query->get('document'));
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the given object type.
+ *
+ * @param Request $request
+ *
+ * @return string|null
+ */
+ public function getObjectType(Request $request)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return 'entity';
+ }
+
+ if (null === $this->mongoOdmConfigManager) {
+ return null;
+ }
+
+ if ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return 'document';
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns easyadmin path for given parameters.
+ *
+ * @param array $parameters
+ *
+ * @return string
+ */
+ public function getEasyAdminPath($entity, $action, array $parameters = [], string $type = 'entity')
+ {
+ if ('entity' === $type) {
+ return $this->easyAdminRouter->generate($entity, $action, $parameters);
+ } elseif ('document' === $type) {
+ return $this->mongoOdmEasyAdminRouter->generate($entity, $action, $parameters);
+ }
+
+ throw new \RuntimeException('Type must be either "entity" or "document".');
+ }
+
+ public function getEasyAdminPathFromRequestParameters(array $parameters)
+ {
+ if (\array_key_exists('entity', $parameters)) {
+ return $this->router->generate('easyadmin', $parameters);
+ } elseif (\array_key_exists('document', $parameters)) {
+ return $this->router->generate('easyadmin_mongo_odm', $parameters);
+ }
+
+ throw new \RuntimeException('Parameters must contain either "entity" or "document" key !');
+ }
+}
diff --git a/src/Twig/EmbeddedListExtension.php b/src/Twig/EmbeddedListExtension.php
index 49e452bb..72006a04 100644
--- a/src/Twig/EmbeddedListExtension.php
+++ b/src/Twig/EmbeddedListExtension.php
@@ -42,8 +42,8 @@ public function getEmbeddedListIdentifier(string $requestUri)
return \md5($requestUri);
}
- public function guessDefaultFilters(string $entityFqcn, string $parentEntityProperty, $parentEntity)
+ public function guessDefaultFilters(string $objectFqcn, string $parentObjectProperty, $parentObject)
{
- return $this->embeddedListHelper->guessDefaultFilter($entityFqcn, $parentEntityProperty, $parentEntity);
+ return $this->embeddedListHelper->guessDefaultFilter($objectFqcn, $parentObjectProperty, $parentObject);
}
}
diff --git a/tests/Configuration/CustomFormTypeConfigPassTest.php b/tests/Configuration/CustomFormTypeConfigPassTest.php
index 3273c624..92f305b0 100644
--- a/tests/Configuration/CustomFormTypeConfigPassTest.php
+++ b/tests/Configuration/CustomFormTypeConfigPassTest.php
@@ -28,6 +28,16 @@ public function testCustomFormTypesAreReplaced()
]],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'form' => ['fields' => ['testField1' => ['type' => 'foo']]],
+ 'edit' => ['fields' => ['testField2' => ['type' => 'bar']]],
+ 'new' => ['fields' => [
+ 'testField1' => ['type' => 'foo'],
+ 'testField2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
];
$backendConfig = $shortFormTypeConfigPass->process($backendConfig);
@@ -53,6 +63,26 @@ public function testCustomFormTypesAreReplaced()
],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'form' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\FooType'],
+ ],
+ ],
+ 'edit' => [
+ 'fields' => [
+ 'testField2' => ['type' => 'AppBundle\Form\Type\BarType'],
+ ],
+ ],
+ 'new' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\FooType'],
+ 'testField2' => ['type' => 'AppBundle\Form\Type\BarType'],
+ ],
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
@@ -76,6 +106,14 @@ public function testLegacyShortFormTypesAreReplaced()
]],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'new' => ['fields' => [
+ 'testField1' => ['type' => 'text'],
+ 'testField2' => ['type' => 'choice'],
+ ]],
+ ],
+ ],
];
$backendConfig = $shortFormTypeConfigPass->process($backendConfig);
@@ -91,6 +129,16 @@ public function testLegacyShortFormTypesAreReplaced()
],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'new' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\TextType'],
+ 'testField2' => ['type' => ChoiceType::class],
+ ],
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
diff --git a/tests/Configuration/EmbeddedListViewConfigPassTest.php b/tests/Configuration/EmbeddedListViewConfigPassTest.php
index 4bcd4c45..723a6015 100644
--- a/tests/Configuration/EmbeddedListViewConfigPassTest.php
+++ b/tests/Configuration/EmbeddedListViewConfigPassTest.php
@@ -22,6 +22,16 @@ public function testOpenNewTabOption()
'embeddedList' => ['open_new_tab' => false],
],
],
+ 'documents' => [
+ 'NotSetDocument' => [
+ ],
+ 'SetTrueDocument' => [
+ 'embeddedList' => ['open_new_tab' => true],
+ ],
+ 'SetFalseDocument' => [
+ 'embeddedList' => ['open_new_tab' => false],
+ ],
+ ],
];
$backendConfig = $embeddedListViewConfigPass->process($backendConfig);
@@ -47,6 +57,23 @@ public function testOpenNewTabOption()
],
],
],
+ 'documents' => [
+ 'NotSetDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => true,
+ ],
+ ],
+ 'SetTrueDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => true,
+ ],
+ ],
+ 'SetFalseDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => false,
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
diff --git a/tests/Configuration/ListFormFiltersConfigPassTest.php b/tests/Configuration/ListFormFiltersConfigPassTest.php
new file mode 100644
index 00000000..86022d6d
--- /dev/null
+++ b/tests/Configuration/ListFormFiltersConfigPassTest.php
@@ -0,0 +1,62 @@
+createMock(ManagerRegistry::class);
+
+ $listFormFiltersConfigPass = new ListFormFiltersConfigPass($doctrineOrm);
+
+ $backendConfig = [
+ 'entities' => [
+ 'TestEntity' => [
+ 'class' => 'App\\Entity\\TestEntity',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo'],
+ 'filter2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
+ 'documents' => [
+ 'TestDocument' => [
+ 'class' => 'App\\Document\\TestDocument',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo'],
+ 'filter2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
+ ];
+
+ $backendConfig = $listFormFiltersConfigPass->process($backendConfig);
+
+ $expectedBackendConfig = [
+ 'entities' => [
+ 'TestEntity' => [
+ 'class' => 'App\\Entity\\TestEntity',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo', 'property' => 'filter1'],
+ 'filter2' => ['type' => 'bar', 'property' => 'filter2'],
+ ]],
+ ],
+ ],
+ 'documents' => [
+ 'TestDocument' => [
+ 'class' => 'App\\Document\\TestDocument',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo', 'property' => 'filter1'],
+ 'filter2' => ['type' => 'bar', 'property' => 'filter2'],
+ ]],
+ ],
+ ],
+ ];
+
+ $this->assertSame($backendConfig, $expectedBackendConfig);
+ }
+}
diff --git a/tests/Configuration/ShowViewConfigPassTest.php b/tests/Configuration/ShowViewConfigPassTest.php
index 3fd68a4d..494e7226 100644
--- a/tests/Configuration/ShowViewConfigPassTest.php
+++ b/tests/Configuration/ShowViewConfigPassTest.php
@@ -58,9 +58,10 @@ public function testDefaultEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => '@EasyAdminExtension/default/field_embedded_list.html.twig',
'template_options' => [
- 'entity_fqcn' => 'App\Entity\MyRelation',
- 'parent_entity_property' => 'relations',
+ 'object_type' => 'entity',
'entity' => 'MyRelation',
+ 'object_fqcn' => 'App\Entity\MyRelation',
+ 'parent_object_property' => 'relations',
'ext_filters' => [],
'hidden_fields' => [],
'max_results' => null,
@@ -104,10 +105,10 @@ public function testDefinedEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => 'path/to/template.html.twig',
'template_options' => [
- 'parent_entity_fqcn' => 'Foo\Entity\MyEntity',
- 'parent_entity_property' => 'children',
- 'entity_fqcn' => 'Foo\Entity\Child',
'entity' => 'Child',
+ 'object_fqcn' => 'Foo\Entity\Child',
+ 'parent_object_fqcn' => 'Foo\Entity\MyEntity',
+ 'parent_object_property' => 'children',
'ext_filters' => ['bar' => 'baz'],
'sort' => ['qux', 'ASC'],
],
@@ -131,14 +132,15 @@ public function testDefinedEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => 'path/to/template.html.twig',
'template_options' => [
- 'parent_entity_fqcn' => 'Foo\Entity\MyEntity',
- 'parent_entity_property' => 'children',
- 'entity_fqcn' => 'Foo\Entity\Child',
'entity' => 'Child',
+ 'object_fqcn' => 'Foo\Entity\Child',
+ 'parent_object_fqcn' => 'Foo\Entity\MyEntity',
+ 'parent_object_property' => 'children',
'ext_filters' => ['bar' => 'baz'],
'sort' => ['field' => 'qux', 'direction' => 'ASC'],
'hidden_fields' => [],
'max_results' => null,
+ 'object_type' => 'entity',
],
],
],
diff --git a/tests/Controller/MongoOdmCompatTest.php b/tests/Controller/MongoOdmCompatTest.php
new file mode 100644
index 00000000..7b8d1b02
--- /dev/null
+++ b/tests/Controller/MongoOdmCompatTest.php
@@ -0,0 +1,45 @@
+initClient(['environment' => 'mongo_odm_compat', 'withMongoOdm' => true]);
+ }
+
+ public function testEasyAdminWorks()
+ {
+ $crawler = $this->requestListView('Product');
+
+ $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+ }
+
+ public function testEasyAdminMongoOdmWorks()
+ {
+ $this->markTestSkipped('The MongoDB test database is not yet available.');
+
+ $crawler = $this->requestMongoOdmListView('RequestLog');
+
+ $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+ }
+
+ /**
+ * @return Crawler
+ */
+ protected function requestMongoOdmListView($documentName = 'RequestLog', array $requestFilters = [], array $formFilters = [])
+ {
+ return $this->getMongoOdmBackendPage([
+ 'action' => 'list',
+ 'document' => $documentName,
+ 'view' => 'list',
+ 'ext_filters' => $requestFilters,
+ 'form_filters' => $formFilters,
+ ]);
+ }
+}
diff --git a/tests/Controller/UserRolesTest.php b/tests/Controller/UserRolesTest.php
index 5aaac370..75949de8 100644
--- a/tests/Controller/UserRolesTest.php
+++ b/tests/Controller/UserRolesTest.php
@@ -116,7 +116,7 @@ public function testEntityActionsAreFilteredOnPrefixedRoles()
$crawler = $this->getBackendPage(['entity' => 'Category', 'action' => 'edit', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_CATEGORY_EDIT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_CATEGORY_EDIT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
@@ -139,7 +139,7 @@ public function testEntityActionsAreFilteredOnSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'show', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
}
@@ -169,19 +169,19 @@ public function testEntityActionsAreForbiddenOnCaseInsensitiveSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'edit', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'Edit', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'EDIT', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_EDIT_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
@@ -189,19 +189,19 @@ public function testEntityActionsAreForbiddenOnCaseInsensitiveSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'show', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'Show', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'SHOW', 'id' => 1]);
$this->assertSame(403, static::$client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this entity action ! (403 Forbidden)',
+ 'You must be granted one of following role(s) [ROLE_TEST_SHOW_PRODUCT] to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
}
diff --git a/tests/Fixtures/AbstractTestCase.php b/tests/Fixtures/AbstractTestCase.php
index 1e3033e0..3ed6c318 100644
--- a/tests/Fixtures/AbstractTestCase.php
+++ b/tests/Fixtures/AbstractTestCase.php
@@ -24,6 +24,20 @@ protected function initClient(array $options = [])
static::$client = static::createClient($options + static::$options);
}
+ /**
+ * {@inheritdoc}
+ */
+ protected static function createKernel(array $options = [])
+ {
+ $kernel = parent::createKernel($options);
+
+ $withMongoOdm = isset($options['withMongoOdm']) ? (bool) $options['withMongoOdm'] : false;
+
+ $kernel->withMongoOdm($withMongoOdm);
+
+ return $kernel;
+ }
+
/**
* It ensures that the database contains the original fixtures of the
* application. This way tests can modify its contents safely without
@@ -50,6 +64,16 @@ protected function getBackendPage(array $queryParameters = [], array $serverPara
return static::$client->request('GET', '/admin/?'.\http_build_query($queryParameters, '', '&'), [], [], $serverParameters);
}
+ /**
+ * @param array $queryParameters
+ *
+ * @return Crawler
+ */
+ protected function getMongoOdmBackendPage(array $queryParameters = [])
+ {
+ return $this->client->request('GET', '/admin-mongo-odm/?'.\http_build_query($queryParameters, '', '&'));
+ }
+
/**
* @return Crawler
*/
diff --git a/tests/Fixtures/App/AppKernel.php b/tests/Fixtures/App/AppKernel.php
index 8b4b171c..931a98ce 100644
--- a/tests/Fixtures/App/AppKernel.php
+++ b/tests/Fixtures/App/AppKernel.php
@@ -10,18 +10,35 @@
*/
class AppKernel extends Kernel
{
+ private $withMongoOdm = false;
+
+ public function withMongoOdm(bool $withMongoOdm)
+ {
+ $this->withMongoOdm = $withMongoOdm;
+
+ return $this;
+ }
+
public function registerBundles()
{
- return [
+ $bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle(),
- new AlterPHP\EasyAdminExtensionBundle\EasyAdminExtensionBundle(),
- new AlterPHP\EasyAdminExtensionBundle\Tests\Fixtures\AppTestBundle\AppTestBundle(),
];
+
+ if ($this->withMongoOdm) {
+ $bundles[] = new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle();
+ $bundles[] = new AlterPHP\EasyAdminMongoOdmBundle\EasyAdminMongoOdmBundle();
+ }
+
+ $bundles[] = new AlterPHP\EasyAdminExtensionBundle\EasyAdminExtensionBundle();
+ $bundles[] = new AlterPHP\EasyAdminExtensionBundle\Tests\Fixtures\AppTestBundle\AppTestBundle();
+
+ return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
diff --git a/tests/Fixtures/App/config/config_mongo_odm_compat.yaml b/tests/Fixtures/App/config/config_mongo_odm_compat.yaml
new file mode 100644
index 00000000..824f4c40
--- /dev/null
+++ b/tests/Fixtures/App/config/config_mongo_odm_compat.yaml
@@ -0,0 +1,47 @@
+imports:
+ - { resource: config.yaml }
+
+framework:
+ router:
+ resource: '%kernel.root_dir%/config/routing_mongo_odm.yaml'
+
+doctrine_mongodb:
+ auto_generate_proxy_classes: '%kernel.debug%'
+ auto_generate_hydrator_classes: '%kernel.debug%'
+ connections:
+ default:
+ server: 'localhost'
+ options:
+ authSource: "admin"
+ db: 'mongo_db'
+ document_managers:
+ default:
+ connection: default
+ database: 'mongo_db'
+ mappings:
+ App:
+ is_bundle: false
+ type: annotation
+ dir: '%kernel.root_dir%/../AppTestBundle/Document/FunctionalTests/'
+ prefix: AppTestBundle\Document\FunctionalTests\
+ alias: FunctionalTests
+ default_document_manager: default
+ default_connection: default
+
+easy_admin:
+ entities:
+ Category:
+ class: AppTestBundle\Entity\FunctionalTests\Category
+ Product:
+ class: AppTestBundle\Entity\FunctionalTests\Product
+ Purchase:
+ class: AppTestBundle\Entity\FunctionalTests\Purchase
+ AdminGroup:
+ class: AppTestBundle\Entity\FunctionalTests\AdminGroup
+ AdminUser:
+ class: AppTestBundle\Entity\FunctionalTests\AdminUser
+
+easy_admin_mongo_odm:
+ documents:
+ RequestLog:
+ class: AppTestBundle\Document\FunctionalTests\RequestLog
diff --git a/tests/Fixtures/App/config/routing_mongo_odm.yaml b/tests/Fixtures/App/config/routing_mongo_odm.yaml
new file mode 100644
index 00000000..839066b0
--- /dev/null
+++ b/tests/Fixtures/App/config/routing_mongo_odm.yaml
@@ -0,0 +1,9 @@
+easy_admin_bundle:
+ resource: "AlterPHP\\EasyAdminExtensionBundle\\Controller\\EasyAdminController"
+ type: annotation
+ prefix: /admin/
+
+easy_admin_mongo_odm_bundle:
+ resource: "AlterPHP\\EasyAdminExtensionBundle\\Controller\\MongoOdmEasyAdminController"
+ type: annotation
+ prefix: /admin-mongo-odm/
diff --git a/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php b/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php
new file mode 100644
index 00000000..b769bcbe
--- /dev/null
+++ b/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php
@@ -0,0 +1,61 @@
+clientIp = $clientIp;
+ $requestLog->localDatetime = $localDatetime ? $localDatetime->format('c') : null;
+
+ return $requestLog;
+ }
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function getClientIp()
+ {
+ return $this->clientIp;
+ }
+
+ public function getLocalDatetime()
+ {
+ return $this->localDatetime;
+ }
+}