Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 20, 2023
2 parents 4f12389 + 5c36c5c commit 776f568
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.18",
"sonata-project/block-bundle": "^4.2",
"sonata-project/block-bundle": "^5.0",
"sonata-project/entity-audit-bundle": "^1.1",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/css-selector": "^5.4 || ^6.2",
Expand Down
1 change: 0 additions & 1 deletion src/Block/AuditBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct(
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
{
$template = $blockContext->getTemplate();
\assert(null !== $template);
$limit = $blockContext->getSetting('limit');
\assert(\is_int($limit));

Expand Down
8 changes: 7 additions & 1 deletion src/Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ private function filterRange(ProxyQueryInterface $query, string $alias, string $
$endDateParameterName = $this->getNewParameterName($query);

if (DateRangeOperatorType::TYPE_NOT_BETWEEN === $type) {
$this->applyWhere($query, sprintf('%s.%s < :%s OR %s.%s > :%s', $alias, $field, $startDateParameterName, $alias, $field, $endDateParameterName));
if (null !== $value['start']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '<', $startDateParameterName));
}

if (null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '>', $endDateParameterName));
}
} else {
if (null !== $value['start']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '>=', $startDateParameterName));
Expand Down
8 changes: 0 additions & 8 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Sonata\AdminBundle\SonataAdminBundle;
use Sonata\BlockBundle\Cache\HttpCacheHandler;
use Sonata\BlockBundle\SonataBlockBundle;
use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
Expand Down Expand Up @@ -79,9 +78,6 @@ protected function configureRoutes(RoutingConfigurator $routes): void
$routes->import(sprintf('%s/config/routes.yaml', $this->getProjectDir()));
}

/**
* @psalm-suppress DeprecatedClass
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('app.base_dir', $this->getBaseDir());
Expand All @@ -92,10 +88,6 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
$loader->load(__DIR__.'/config/config_symfony_v5.yml');
}

if (class_exists(HttpCacheHandler::class)) {
$loader->load($this->getProjectDir().'/config/config_sonata_block_v4.yaml');
}

$loader->load(__DIR__.'/config/services.php');
}

Expand Down
1 change: 1 addition & 0 deletions tests/App/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ doctrine:
sonata_admin:
options:
html5_validate: false
use_stickyforms: false
2 changes: 0 additions & 2 deletions tests/App/config/config_sonata_block_v4.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Block/AuditBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public function testDefaultSettings(): void

self::assertSettings([
'attr' => [],
'extra_cache_keys' => [],
'limit' => 10,
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
'ttl' => 0,
'use_cache' => true,
], $blockContext);
}
}
45 changes: 45 additions & 0 deletions tests/Filter/DateTimeRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter;

use Sonata\AdminBundle\Filter\Model\FilterData;
use Sonata\AdminBundle\Form\Type\Operator\DateRangeOperatorType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\DoctrineORMAdminBundle\Filter\DateTimeRangeFilter;
use Sonata\Form\Type\DateTimeRangeType;
Expand Down Expand Up @@ -43,4 +44,48 @@ public function testGetType(): void

static::assertSame(DateTimeRangeType::class, $filter->getFieldType());
}

public function testFilterNotBetweenStartDate(): void
{
$filter = new DateTimeRangeFilter();
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);

$proxyQuery = new ProxyQuery($this->createQueryBuilderStub());

$startDateTime = new \DateTime('2023-10-03T12:00:01');

$filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray([
'type' => DateRangeOperatorType::TYPE_NOT_BETWEEN,
'value' => [
'start' => $startDateTime,
'end' => null,
],
]));

self::assertSameQuery(['WHERE alias.field < :field_name_0'], $proxyQuery);
self::assertSameQueryParameters(['field_name_0' => $startDateTime], $proxyQuery);
static::assertTrue($filter->isActive());
}

public function testFilterNotBetweenEndDate(): void
{
$filter = new DateTimeRangeFilter();
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);

$proxyQuery = new ProxyQuery($this->createQueryBuilderStub());

$endDateTime = new \DateTime('2023-10-03T12:00:01');

$filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray([
'type' => DateRangeOperatorType::TYPE_NOT_BETWEEN,
'value' => [
'start' => null,
'end' => $endDateTime,
],
]));

self::assertSameQuery(['WHERE alias.field > :field_name_1'], $proxyQuery);
self::assertSameQueryParameters(['field_name_1' => $endDateTime], $proxyQuery);
static::assertTrue($filter->isActive());
}
}
2 changes: 1 addition & 1 deletion tests/Functional/BasePantherTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class BasePantherTestCase extends PantherTestCase
protected function setUp(): void
{
$this->client = static::createPantherClient([
'browser' => PantherTestCase::CHROME,
'browser' => PantherTestCase::FIREFOX,
'connection_timeout_in_ms' => 5000,
'request_timeout_in_ms' => 60000,
]);
Expand Down

0 comments on commit 776f568

Please sign in to comment.