-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to ModelManager and DateFilter
- Loading branch information
Showing
15 changed files
with
632 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Filter; | ||
|
||
use Sonata\AdminBundle\Form\Type\Filter\DateType; | ||
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery; | ||
use Sonata\DoctrineMongoDBAdminBundle\Filter\DateTimeFilter; | ||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; | ||
|
||
final class DateTimeFilterTest extends FilterWithQueryBuilderTest | ||
{ | ||
public function testEmpty(): void | ||
{ | ||
$filter = new DateTimeFilter(); | ||
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); | ||
|
||
$builder = new ProxyQuery($this->getQueryBuilder()); | ||
|
||
$builder->getQueryBuilder() | ||
->expects($this->never()) | ||
->method('field') | ||
; | ||
|
||
$filter->filter($builder, 'alias', 'field', null); | ||
$filter->filter($builder, 'alias', 'field', ''); | ||
$filter->filter($builder, 'alias', 'field', []); | ||
|
||
$this->assertFalse($filter->isActive()); | ||
} | ||
|
||
public function testGetType(): void | ||
{ | ||
$this->assertSame(DateTimeType::class, (new DateTimeFilter())->getFieldType()); | ||
} | ||
|
||
/** | ||
* @dataProvider getExamples | ||
*/ | ||
public function testFilter(array $data, string $method): void | ||
{ | ||
$filter = new DateTimeFilter(); | ||
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); | ||
|
||
$builder = new ProxyQuery($this->getQueryBuilder()); | ||
|
||
$builder->getQueryBuilder() | ||
->expects($this->once()) | ||
->method($method) | ||
->with($data['value'] ?? null) | ||
; | ||
|
||
$filter->filter($builder, 'alias', 'field', $data); | ||
|
||
$this->assertTrue($filter->isActive()); | ||
} | ||
|
||
public function getExamples(): array | ||
{ | ||
return [ | ||
[['type' => DateType::TYPE_EQUAL, 'value' => new \DateTime('now')], 'range'], | ||
[['type' => DateType::TYPE_GREATER_EQUAL, 'value' => new \DateTime('now')], 'gte'], | ||
[['type' => DateType::TYPE_GREATER_THAN, 'value' => new \DateTime('now')], 'gt'], | ||
[['type' => DateType::TYPE_LESS_EQUAL, 'value' => new \DateTime('now')], 'lte'], | ||
[['type' => DateType::TYPE_LESS_THAN, 'value' => new \DateTime('now')], 'lt'], | ||
[['type' => DateType::TYPE_NULL], 'equals'], | ||
[['type' => DateType::TYPE_NOT_NULL], 'notEqual'], | ||
[['value' => new \DateTime('now')], 'range'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document; | ||
|
||
abstract class AbstractDocument | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document; | ||
|
||
class AssociatedDocument | ||
{ | ||
private $plainField; | ||
private $embeddedDocument; | ||
|
||
public function __construct(int $plainField, EmbeddedDocument $embeddedDocument) | ||
{ | ||
$this->plainField = $plainField; | ||
$this->embeddedDocument = $embeddedDocument; | ||
} | ||
|
||
public function getPlainField(): int | ||
{ | ||
return $this->plainField; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document; | ||
|
||
class ContainerDocument | ||
{ | ||
private $plainField; | ||
private $associatedDocument; | ||
private $embeddedDocument; | ||
|
||
public function __construct(AssociatedDocument $associatedDocument, EmbeddedDocument $embeddedDocument) | ||
{ | ||
$this->associatedDocument = $associatedDocument; | ||
$this->embeddedDocument = $embeddedDocument; | ||
} | ||
|
||
public function getAssociatedDocument(): AssociatedDocument | ||
{ | ||
return $this->associatedDocument; | ||
} | ||
} |
Oops, something went wrong.