Skip to content

Commit

Permalink
Tests + renaming variables
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Mar 31, 2018
1 parent e9ac26d commit e2a056e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/Configuration/EmbeddedListViewConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/EasyAdminExtensionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tag name="easyadmin.config_pass" priority="41"/>
</service>
<service id="alterphp.easyadmin_extension.config_pass.embedded_list_view" class="AlterPHP\EasyAdminExtensionBundle\Configuration\EmbeddedListViewConfigPass">
<argument>%easy_admin_extension.embedded_list.open_in_new_tab_link%</argument>
<argument>%easy_admin_extension.embedded_list.open_new_tab%</argument>
<!-- Makes it process just after ViewConfigPass -->
<tag name="easyadmin.config_pass" priority="29"/>
</service>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/default/embedded_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
{% endblock table_body %}
</tbody>

{% if _entity_config.embeddedList.open_in_new_tab_link %}
{% if _entity_config.embeddedList.open_new_tab %}
<tfoot>
<tr>
<td colspan="{{ _columns_count }}" class="text-center">
{% block open_new_tab %}
<a class="btn btn-info btn-xs" title="{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}" target="_blank" href="{{ path('easyadmin', _request_parameters|merge({action: 'list'})) }}">
<a class="btn btn-info btn-xs open-new-tab" title="{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}" target="_blank" href="{{ path('easyadmin', _request_parameters|merge({action: 'list'})) }}">
<i class="fa fa-external-link-square"></i>
<span>{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}</span>
</a>
Expand Down
50 changes: 50 additions & 0 deletions tests/Configuration/EmbeddedListViewConfigPassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace AlterPHP\EasyAdminExtensionBundle\Tests\Configuration;

use AlterPHP\EasyAdminExtensionBundle\Configuration\EmbeddedListViewConfigPass;

class EmbeddedListViewConfigPassTest extends \PHPUnit_Framework_TestCase
{
public function testOpenNewTabOption()
{
$embeddedListViewConfigPass = new EmbeddedListViewConfigPass(true);

$backendConfig = array(
'entities' => 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);
}
}
14 changes: 14 additions & 0 deletions tests/Controller/EmbeddedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/App/config/config_embedded_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,4 +22,5 @@ easy_admin:
Purchase:
class: AppTestBundle\Entity\FunctionalTests\Purchase
embeddedList:
open_new_tab: true
sort: [createdAt, DESC]

0 comments on commit e2a056e

Please sign in to comment.