Skip to content

Commit

Permalink
Merge b2fae09 into 06ae939
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Dec 15, 2020
2 parents 06ae939 + b2fae09 commit 506938e
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 154 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
language: php

php:
- 5.6
- 7.0
- 7.2
- 7.3

matrix:
include:
- php: 5.6
- php: 7.2
env: |
SYMFONY_VERSION=2.7.*
- php: 5.6
env: |
SYMFONY_VERSION=2.8.*
- php: 7.1
SYMFONY_VERSION=^3.0
- php: 7.2
env: |
SYMFONY_VERSION=^4.0
before_install:
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- |
if [ "${SYMFONY_VERSION}" != "" ]; then
packages="form dependency-injection config http-foundation http-kernel options-resolver security serializer"
packages="form dependency-injection config http-foundation http-kernel options-resolver security-guard serializer"
devpackages="framework-bundle browser-kit templating expression-language"
for package in $packages
do
Expand All @@ -31,10 +29,6 @@ before_install:
done
fi;
before_script:
- echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

install:
- travis_retry composer self-update
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
Expand All @@ -46,4 +40,4 @@ script:
- php vendor/bin/phpunit -c phpunit.xml.dist

after_success:
- php vendor/bin/coveralls
- php vendor/bin/php-coveralls
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('apy_data_grid');
$treeBuilder = new TreeBuilder('apy_data_grid');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
2 changes: 1 addition & 1 deletion Grid/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public function getFilters($source)
{
$filters = [];

if ($this->hasOperator($this->data['operator'])) {
if (isset($this->data['operator']) && $this->hasOperator($this->data['operator'])) {
if ($this instanceof ArrayColumn && in_array($this->data['operator'], [self::OPERATOR_EQ, self::OPERATOR_NEQ])) {
$filters[] = new Filter($this->data['operator'], $this->data['from']);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected function getTemplatesFromString($theme)
$templates = [];

$template = $this->twig->loadTemplate($theme);
while ($template instanceof \Twig_Template) {
while ($template instanceof TemplateWrapper) {
$templates[] = $template;
$template = $template->getParent([]);
}
Expand Down
12 changes: 7 additions & 5 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\TemplateWrapper;

class Grid implements GridInterface
{
Expand Down Expand Up @@ -359,8 +360,10 @@ public function initialize()
$this->setPersistence($config->isPersisted());

// Route parameters
$routeParameters = $config->getRouteParameters();
if (!empty($routeParameters)) {
$routeParameters = [];
$parameters = $config->getRouteParameters();
if (!empty($parameters)) {
$routeParameters = $parameters;
foreach ($routeParameters as $parameter => $value) {
$this->setRouteParameter($parameter, $value);
}
Expand Down Expand Up @@ -1135,7 +1138,7 @@ protected function set($key, $data)

protected function saveSession()
{
if (!empty($this->sessionData)) {
if (!empty($this->sessionData) && !empty($this->hash)) {
$this->session->set($this->hash, $this->sessionData);
}
}
Expand Down Expand Up @@ -1395,12 +1398,11 @@ public function getRowActions()
public function setTemplate($template)
{
if ($template !== null) {
if ($template instanceof \Twig_Template) {
if ($template instanceof TemplateWrapper) {
$template = '__SELF__' . $template->getTemplateName();
} elseif (!is_string($template)) {
throw new \Exception(self::TWIG_TEMPLATE_LOAD_EX_MSG);
}

$this->set(self::REQUEST_QUERY_TEMPLATE, $template);
$this->saveSession();
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/blocks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
{% endblock grid_pager %}
{# ---------------------------------------------------- grid_pager_totalcount -------------------------------------------------- #}
{% block grid_pager_totalcount %}
{{ '%count% Results, ' | transchoice(grid.totalCount, {'%count%': grid.totalCount}) }}
{{ '%count% Results, ' | trans({'%count%': grid.totalCount}) }}
{% endblock grid_pager_totalcount %}
{# ---------------------------------------------------- grid_pager_selectpage -------------------------------------------------- #}
{% block grid_pager_selectpage %}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Grid/Column/TextColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Column\TextColumn;
use APY\DataGridBundle\Grid\Filter;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TextColumnTest extends TestCase
class TextColumnTest extends WebTestCase
{
/** @var TextColumn */
private $column;
Expand Down
78 changes: 46 additions & 32 deletions Tests/Grid/GridBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException;
use APY\DataGridBundle\Grid\Grid;
use APY\DataGridBundle\Grid\GridBuilder;
use APY\DataGridBundle\Grid\GridBuilderInterface;
use APY\DataGridBundle\Grid\GridFactory;
use APY\DataGridBundle\Grid\GridFactoryInterface;
use APY\DataGridBundle\Grid\GridRegistryInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

Expand All @@ -30,11 +36,51 @@ class GridBuilderTest extends TestCase
*/
private $factory;

private $registry;

/**
* @var GridBuilder
*/
private $builder;

/**
* {@inheritdoc}
*/
protected function setUp()
{
//self::bootKernel();

// returns the real and unchanged service container
//$container = self::$kernel->getContainer();
//$container = self::$container;
//$this->container = $container;
$self = $this;
$this->container = $this->createMock(Container::class);
$this->container->expects($this->any())
->method('get')
->will($this->returnCallback(function ($param) use ($self) {
switch ($param) {
case 'router':
return $self->createMock(RouterInterface::class);
break;
case 'request_stack':
$request = new Request([], [], ['key' => 'value']);
$session = new Session();
$request->setSession($session);
$requestStack = new RequestStack();
$requestStack->push($request);
return $requestStack;
break;
case 'security.authorization_checker':
return $self->createMock(AuthorizationCheckerInterface::class);
break;
}
}));

$this->factory = $this->createMock(GridFactoryInterface::class);
$this->builder = new GridBuilder($this->container, $this->factory, 'name');
}

public function testAddUnexpectedType()
{
$this->expectException(UnexpectedTypeException::class);
Expand Down Expand Up @@ -140,38 +186,6 @@ public function testGetGrid()
$this->assertInstanceOf(Grid::class, $this->builder->getGrid());
}

/**
* {@inheritdoc}
*/
protected function setUp()
{
$self = $this;

$this->container = $this->createMock(Container::class);
$this->container->expects($this->any())
->method('get')
->will($this->returnCallback(function ($param) use ($self) {
switch ($param) {
case 'router':
return $self->createMock(RouterInterface::class);
break;
case 'request_stack':
$request = new Request([], [], ['key' => 'value']);
$requestStack = new RequestStack();
$requestStack->push($request);

return $requestStack;
break;
case 'security.authorization_checker':
return $self->createMock(AuthorizationCheckerInterface::class);
break;
}
}));

$this->factory = $this->createMock(GridFactoryInterface::class);
$this->builder = new GridBuilder($this->container, $this->factory, 'name');
}

protected function tearDown()
{
$this->factory = null;
Expand Down
3 changes: 3 additions & 0 deletions Tests/Grid/GridFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
Expand Down Expand Up @@ -172,6 +173,8 @@ protected function setUp()
break;
case 'request_stack':
$request = new Request([], [], ['key' => 'value']);
$session = new Session();
$request->setSession($session);
$requestStack = new RequestStack();
$requestStack->push($request);

Expand Down
3 changes: 1 addition & 2 deletions Tests/Grid/GridManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use APY\DataGridBundle\Grid\Grid;
use APY\DataGridBundle\Grid\GridManager;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;

class GridManagerTest extends TestCase
{
Expand Down
30 changes: 22 additions & 8 deletions Tests/Grid/GridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use APY\DataGridBundle\Grid\Rows;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Source\Source;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Templating\EngineInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\ParameterBag;
Expand All @@ -31,6 +31,7 @@
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Twig\TemplateWrapper;

class GridTest extends TestCase
{
Expand Down Expand Up @@ -177,7 +178,7 @@ public function testInitializeRouteUrlWithParams()
$this
->router
->method('generate')
->with($route, null)
->with($route, [])
->willReturn($url);

$this->grid->initialize();
Expand Down Expand Up @@ -737,9 +738,8 @@ public function testGetRowActions()
public function testSetExportTwigTemplateInstance()
{
$templateName = 'templateName';

$template = $this
->getMockBuilder(\Twig_Template::class)
->getMockBuilder(TemplateWrapper::class)
->disableOriginalConstructor()
->getMock();
$template
Expand Down Expand Up @@ -767,6 +767,10 @@ public function testSetExportStringTemplate()
->method('set')
->with($this->anything(), [Grid::REQUEST_QUERY_TEMPLATE => $template]);


$this->arrangeGridSourceDataLoadedWithEmptyRows();
$this->arrangeGridPrimaryColumn();
$this->grid->handleRequest($this->request);
$this->grid->setTemplate($template);
}

Expand Down Expand Up @@ -800,7 +804,7 @@ public function testReturnTwigTemplate()
$templateName = 'templateName';

$template = $this
->getMockBuilder(\Twig_Template::class)
->getMockBuilder(TemplateWrapper::class)
->disableOriginalConstructor()
->getMock();
$template
Expand Down Expand Up @@ -2593,6 +2597,9 @@ public function testRaiseExceptionIfGetNonExistentTweak()
$tweakId = 'aValidTweakId';
$tweak = ['filters' => [], 'order' => 'columnId', 'page' => 1, 'limit' => 50, 'export' => 1, 'massAction' => 1];

$routeUrl = 'http://www.foo.com';
$this->grid->setRouteUrl($routeUrl);

$this->grid->addTweak('title', $tweak, $tweakId, 'group');

$this->grid->getTweak($nonExistentTweak);
Expand All @@ -2603,8 +2610,12 @@ public function testGetTweak()
$title = 'aTweak';
$id = 'aValidTweakId';
$group = 'tweakGroup';

$routeUrl = 'http://www.foo.com';
$this->grid->setRouteUrl($routeUrl);

$tweak = ['filters' => [], 'order' => 'columnId', 'page' => 1, 'limit' => 50, 'export' => 1, 'massAction' => 1];
$tweakUrl = sprintf('?[%s]=%s', Grid::REQUEST_QUERY_TWEAK, $id);
$tweakUrl = $routeUrl.sprintf('?[%s]=%s', Grid::REQUEST_QUERY_TWEAK, $id);

$this->grid->addTweak($title, $tweak, $id, $group);

Expand All @@ -2615,11 +2626,14 @@ public function testGetTweak()

public function testGetTweaksByGroupExcludingThoseWhoDoNotHaveTheGroup()
{
$routeUrl = 'http://www.foo.com';
$this->grid->setRouteUrl($routeUrl);

$title = 'aTweak';
$id = 'aValidTweakId';
$group = 'tweakGroup';
$tweak = ['filters' => [], 'order' => 'columnId', 'page' => 1, 'limit' => 50, 'export' => 1, 'massAction' => 1];
$tweakUrl = sprintf('?[%s]=%s', Grid::REQUEST_QUERY_TWEAK, $id);
$tweakUrl = $routeUrl.sprintf('?[%s]=%s', Grid::REQUEST_QUERY_TWEAK, $id);
$tweakResult = [$id => array_merge(['title' => $title, 'id' => $id, 'group' => $group, 'url' => $tweakUrl], $tweak)];

$this->grid->addTweak($title, $tweak, $id, $group);
Expand Down

0 comments on commit 506938e

Please sign in to comment.