From e2a056e4bd9038d9c9fc08e4489a266c00ab5869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sat, 31 Mar 2018 15:33:20 +0200 Subject: [PATCH] Tests + renaming variables --- .../EmbeddedListViewConfigPass.php | 14 +++--- src/DependencyInjection/Configuration.php | 2 +- .../EasyAdminExtensionExtension.php | 4 +- src/Resources/config/services.xml | 2 +- .../views/default/embedded_list.html.twig | 4 +- .../EmbeddedListViewConfigPassTest.php | 50 +++++++++++++++++++ tests/Controller/EmbeddedListTest.php | 14 ++++++ .../App/config/config_embedded_list.yml | 3 ++ 8 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 tests/Configuration/EmbeddedListViewConfigPassTest.php diff --git a/src/Configuration/EmbeddedListViewConfigPass.php b/src/Configuration/EmbeddedListViewConfigPass.php index f0a90ab..d9cbaf3 100644 --- a/src/Configuration/EmbeddedListViewConfigPass.php +++ b/src/Configuration/EmbeddedListViewConfigPass.php @@ -10,17 +10,17 @@ */ class EmbeddedListViewConfigPass implements ConfigPassInterface { - private $defaultOpenInNewTabLink; + private $defaultOpenNewTab; - public function __construct($defaultOpenInNewTabLink) + public function __construct($defaultOpenNewTab) { - $this->defaultOpenInNewTabLink = $defaultOpenInNewTabLink; + $this->defaultOpenNewTab = $defaultOpenNewTab; } public function process(array $backendConfig) { $backendConfig = $this->processSortingConfig($backendConfig); - $backendConfig = $this->processOpenInNewTabLinkConfig($backendConfig); + $backendConfig = $this->processOpenNewTabConfig($backendConfig); return $backendConfig; } @@ -30,11 +30,11 @@ public function process(array $backendConfig) * * @return array */ - private function processOpenInNewTabLinkConfig(array $backendConfig) + private function processOpenNewTabConfig(array $backendConfig) { foreach ($backendConfig['entities'] as $entityName => $entityConfig) { - if (!isset($entityConfig['embeddedList']['open_in_new_tab_link'])) { - $backendConfig['entities'][$entityName]['embeddedList']['open_in_new_tab_link'] = $this->defaultOpenInNewTabLink; + if (!isset($entityConfig['embeddedList']['open_new_tab'])) { + $backendConfig['entities'][$entityName]['embeddedList']['open_new_tab'] = $this->defaultOpenNewTab; } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 73d5e48..f8d96b1 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -39,7 +39,7 @@ public function getConfigTreeBuilder() ->arrayNode('embedded_list') ->addDefaultsIfNotSet() ->children() - ->booleanNode('open_in_new_tab_link') + ->booleanNode('open_new_tab') ->defaultTrue() ->end() ->end() diff --git a/src/DependencyInjection/EasyAdminExtensionExtension.php b/src/DependencyInjection/EasyAdminExtensionExtension.php index 35f2d64..c9ce40c 100644 --- a/src/DependencyInjection/EasyAdminExtensionExtension.php +++ b/src/DependencyInjection/EasyAdminExtensionExtension.php @@ -25,8 +25,8 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('easy_admin_extension.custom_form_types', $config['custom_form_types']); $container->setParameter('easy_admin_extension.minimum_role', $config['minimum_role']); $container->setParameter( - 'easy_admin_extension.embedded_list.open_in_new_tab_link', - $config['embedded_list']['open_in_new_tab_link'] + 'easy_admin_extension.embedded_list.open_new_tab', + $config['embedded_list']['open_new_tab'] ); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index e0d049d..e95498d 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -13,7 +13,7 @@ - %easy_admin_extension.embedded_list.open_in_new_tab_link% + %easy_admin_extension.embedded_list.open_new_tab% diff --git a/src/Resources/views/default/embedded_list.html.twig b/src/Resources/views/default/embedded_list.html.twig index be0ece5..629fe14 100644 --- a/src/Resources/views/default/embedded_list.html.twig +++ b/src/Resources/views/default/embedded_list.html.twig @@ -98,12 +98,12 @@ {% endblock table_body %} - {% if _entity_config.embeddedList.open_in_new_tab_link %} + {% if _entity_config.embeddedList.open_new_tab %} {% block open_new_tab %} - + {{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }} diff --git a/tests/Configuration/EmbeddedListViewConfigPassTest.php b/tests/Configuration/EmbeddedListViewConfigPassTest.php new file mode 100644 index 0000000..2e785b2 --- /dev/null +++ b/tests/Configuration/EmbeddedListViewConfigPassTest.php @@ -0,0 +1,50 @@ + array( + 'NotSetEntity' => array( + ), + 'SetTrueEntity' => array( + 'embeddedList' => array('open_new_tab' => true) + ), + 'SetFalseEntity' => array( + 'embeddedList' => array('open_new_tab' => false) + ), + ), + ); + + $backendConfig = $embeddedListViewConfigPass->process($backendConfig); + + $expectedBackendConfig = array( + 'entities' => array( + 'NotSetEntity' => array( + 'embeddedList' => array( + 'open_new_tab' => true, + ), + ), + 'SetTrueEntity' => array( + 'embeddedList' => array( + 'open_new_tab' => true, + ), + ), + 'SetFalseEntity' => array( + 'embeddedList' => array( + 'open_new_tab' => false, + ), + ), + ), + ); + + $this->assertSame($backendConfig, $expectedBackendConfig); + } +} diff --git a/tests/Controller/EmbeddedListTest.php b/tests/Controller/EmbeddedListTest.php index 2d5de64..b7b5dcf 100644 --- a/tests/Controller/EmbeddedListTest.php +++ b/tests/Controller/EmbeddedListTest.php @@ -138,4 +138,18 @@ public function testDefinedSortIsUsedForEmbedddLists() $this->assertSame(1, $crawler->filter('.embedded-list[for="'.$forAttrValue.'"] '.$createdAtTh)->count()); } + + public function testDefaultOpenNewTabConfigForEmbedddLists() + { + $crawler = $this->getBackendPage(array('entity' => 'Product', 'action' => 'embeddedList')); + + $this->assertSame(0, $crawler->filter('.embedded-list .open-new-tab')->count()); + } + + public function testSetOpenNewTabConfigForEmbedddLists() + { + $crawler = $this->getBackendPage(array('entity' => 'Purchase', 'action' => 'embeddedList')); + + $this->assertSame(1, $crawler->filter('.embedded-list .open-new-tab')->count()); + } } diff --git a/tests/Fixtures/App/config/config_embedded_list.yml b/tests/Fixtures/App/config/config_embedded_list.yml index 1e8d090..ac668a6 100644 --- a/tests/Fixtures/App/config/config_embedded_list.yml +++ b/tests/Fixtures/App/config/config_embedded_list.yml @@ -4,6 +4,8 @@ imports: easy_admin_extension: custom_form_types: embedded_list: AlterPHP\EasyAdminExtensionBundle\Form\Type\EasyAdminEmbeddedListType + embedded_list: + open_new_tab: false easy_admin: entities: @@ -20,4 +22,5 @@ easy_admin: Purchase: class: AppTestBundle\Entity\FunctionalTests\Purchase embeddedList: + open_new_tab: true sort: [createdAt, DESC]