From 957b197196e0080548e97d541fb783b1050ce43a Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Fri, 8 Dec 2023 15:10:14 -0500 Subject: [PATCH] Another batch of mapping tests refactored --- tests/Gedmo/Mapping/Fixture/Embedded.php | 34 +++++ tests/Gedmo/Mapping/Fixture/Loggable.php | 5 +- .../Mapping/Fixture/LoggableComposite.php | 5 +- .../Fixture/LoggableCompositeRelation.php | 5 +- .../Mapping/Fixture/LoggableWithEmbedded.php | 61 ++++++++ tests/Gedmo/Mapping/Fixture/Sluggable.php | 20 ++- tests/Gedmo/Mapping/Fixture/Sortable.php | 103 +++++++++++++ tests/Gedmo/Mapping/Fixture/SortableGroup.php | 17 ++- tests/Gedmo/Mapping/Fixture/Uploadable.php | 86 +++++++++++ .../Gedmo/Mapping/LoggableORMMappingTest.php | 138 +++++++++++++++++- tests/Gedmo/Mapping/SluggableMappingTest.php | 84 +++++++---- tests/Gedmo/Mapping/SortableMappingTest.php | 64 ++++---- .../Mapping/TimestampableMappingTest.php | 84 +++++++---- tests/Gedmo/Mapping/UploadableMappingTest.php | 63 +++++--- .../Gedmo/Mapping/Xml/LoggableMappingTest.php | 132 ----------------- .../Mapping/Xml/SluggableMappingTest.php | 109 -------------- .../Mapping/Xml/SoftDeleteableMappingTest.php | 71 --------- .../Gedmo/Mapping/Xml/SortableMappingTest.php | 72 --------- .../Mapping/Xml/TimestampableMappingTest.php | 69 --------- .../Mapping/Xml/UploadableMappingTest.php | 82 ----------- .../Mapping/Yaml/LoggableMappingTest.php | 111 -------------- 21 files changed, 643 insertions(+), 772 deletions(-) create mode 100644 tests/Gedmo/Mapping/Fixture/Embedded.php create mode 100644 tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php create mode 100644 tests/Gedmo/Mapping/Fixture/Sortable.php create mode 100644 tests/Gedmo/Mapping/Fixture/Uploadable.php delete mode 100644 tests/Gedmo/Mapping/Xml/LoggableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Xml/SluggableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Xml/SoftDeleteableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Xml/SortableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Xml/TimestampableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Xml/UploadableMappingTest.php delete mode 100644 tests/Gedmo/Mapping/Yaml/LoggableMappingTest.php diff --git a/tests/Gedmo/Mapping/Fixture/Embedded.php b/tests/Gedmo/Mapping/Fixture/Embedded.php new file mode 100644 index 0000000000..13f607680f --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/Embedded.php @@ -0,0 +1,34 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture; + +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping as ORM; + +/** + * Class Embedded + * + * @author Fabian Sabau + * + * @ORM\Embeddable + */ +#[ORM\Embeddable] +class Embedded +{ + /** + * @var string + * + * @ORM\Column(type="string") + */ + #[ORM\Column(type: Types::STRING)] + private $subtitle; +} diff --git a/tests/Gedmo/Mapping/Fixture/Loggable.php b/tests/Gedmo/Mapping/Fixture/Loggable.php index 656b7f0e3c..ddc27024d5 100644 --- a/tests/Gedmo/Mapping/Fixture/Loggable.php +++ b/tests/Gedmo/Mapping/Fixture/Loggable.php @@ -11,15 +11,16 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Mapping\Annotation as Gedmo; /** * @ORM\Entity * - * @Gedmo\Loggable + * @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry") */ #[ORM\Entity] -#[Gedmo\Loggable] +#[Gedmo\Loggable(logEntryClass: LogEntry::class)] class Loggable { /** diff --git a/tests/Gedmo/Mapping/Fixture/LoggableComposite.php b/tests/Gedmo/Mapping/Fixture/LoggableComposite.php index c87de73324..9af9f2116c 100644 --- a/tests/Gedmo/Mapping/Fixture/LoggableComposite.php +++ b/tests/Gedmo/Mapping/Fixture/LoggableComposite.php @@ -11,15 +11,16 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Mapping\Annotation as Gedmo; /** * @ORM\Entity * - * @Gedmo\Loggable + * @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry") */ #[ORM\Entity] -#[Gedmo\Loggable] +#[Gedmo\Loggable(logEntryClass: LogEntry::class)] class LoggableComposite { /** diff --git a/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php b/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php index d15ee1c94a..6244fe9f5b 100644 --- a/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php +++ b/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php @@ -11,15 +11,16 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Mapping\Annotation as Gedmo; /** * @ORM\Entity * - * @Gedmo\Loggable + * @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry") */ #[ORM\Entity] -#[Gedmo\Loggable] +#[Gedmo\Loggable(logEntryClass: LogEntry::class)] class LoggableCompositeRelation { /** diff --git a/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php b/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php new file mode 100644 index 0000000000..77c36f7a75 --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php @@ -0,0 +1,61 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture; + +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping as ORM; +use Gedmo\Loggable\Entity\LogEntry; +use Gedmo\Mapping\Annotation as Gedmo; + +/** + * @ORM\Entity + * + * @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry") + */ +#[ORM\Entity] +#[Gedmo\Loggable(logEntryClass: LogEntry::class)] +class LoggableWithEmbedded +{ + /** + * @var int + * + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + private $id; + + /** + * @var string + * + * @ORM\Column(name="title", type="string") + * + * @Gedmo\Versioned + */ + #[ORM\Column(name: 'title', type: Types::STRING)] + #[Gedmo\Versioned] + private $title; + + /** + * @var Embedded + * + * @ORM\Embedded(class="Gedmo\Tests\Mapping\Fixture\Embedded") + * + * @Gedmo\Versioned + */ + #[ORM\Embedded(class: Embedded::class)] + #[Gedmo\Versioned] + private $embedded; +} diff --git a/tests/Gedmo/Mapping/Fixture/Sluggable.php b/tests/Gedmo/Mapping/Fixture/Sluggable.php index b49a35860a..707d27acc8 100644 --- a/tests/Gedmo/Mapping/Fixture/Sluggable.php +++ b/tests/Gedmo/Mapping/Fixture/Sluggable.php @@ -44,9 +44,15 @@ class Sluggable /** * @ORM\Column(name="code", type="string", length=16) */ - #[ORM\Column(name: 'code', type: Types::STRING, length: 64, nullable: true)] + #[ORM\Column(name: 'code', type: Types::STRING, length: 16, nullable: true)] private ?string $code = null; + /** + * @ORM\Column(name="ean", type="string", length=13) + */ + #[ORM\Column(name: 'ean', type: Types::STRING, length: 13, nullable: true)] + private ?string $ean = null; + /** * @var string|null * @@ -56,17 +62,17 @@ class Sluggable * @Gedmo\SlugHandlerOption(name="separator", value="/") * }), * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={ - * @Gedmo\SlugHandlerOption(name="relationField", value="user"), - * @Gedmo\SlugHandlerOption(name="relationSlugField", value="slug"), - * @Gedmo\SlugHandlerOption(name="separator", value="/") + * @Gedmo\SlugHandlerOption(name="relationField", value="parent"), + * @Gedmo\SlugHandlerOption(name="relationSlugField", value="test"), + * @Gedmo\SlugHandlerOption(name="separator", value="-") * }) - * }, separator="-", updatable=false, fields={"title", "code"}) + * }, separator="_", updatable=false, fields={"title", "ean", "code"}, style="camel") * * @ORM\Column(name="slug", type="string", length=64, unique=true) */ - #[Gedmo\Slug(separator: '-', updatable: false, fields: ['title', 'code'])] + #[Gedmo\Slug(separator: '_', updatable: false, fields: ['title', 'ean', 'code'], style: 'camel')] #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] - #[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'user', 'relationSlugField' => 'slug', 'separator' => '/'])] + #[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'parent', 'relationSlugField' => 'test', 'separator' => '-'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] private $slug; diff --git a/tests/Gedmo/Mapping/Fixture/Sortable.php b/tests/Gedmo/Mapping/Fixture/Sortable.php new file mode 100644 index 0000000000..ca03ce2c61 --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/Sortable.php @@ -0,0 +1,103 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; + +/** + * @ORM\Entity + * @ORM\Table(name="sortables") + */ +#[ORM\Entity] +#[ORM\Table(name: 'sortables')] +class Sortable +{ + /** + * @var int + * + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + private $id; + + /** + * @var string + * + * @ORM\Column(type="string", length=128) + */ + #[ORM\Column(type: Types::STRING, length: 128)] + private $title; + + /** + * @var int + * + * @ORM\Column(type="integer") + * + * @Gedmo\SortablePosition + */ + #[ORM\Column(type: Types::INTEGER)] + #[Gedmo\SortablePosition] + private $position; + + /** + * @var string + * + * @ORM\Column(type="string", length=128) + * + * @Gedmo\SortableGroup + */ + #[ORM\Column(type: Types::STRING, length: 128)] + #[Gedmo\SortableGroup] + private $grouping; + + /** + * @var SortableGroup + * + * @ORM\ManyToOne(targetEntity="Sluggable") + * + * @Gedmo\SortableGroup + */ + #[ORM\ManyToOne(targetEntity: SortableGroup::class)] + #[Gedmo\SortableGroup] + private $sortable_group; + + /** + * @var Collection + * + * @ORM\ManyToMany(targetEntity="SortableGroup") + * @ORM\JoinTable(name="sortable_sortable_groups", + * joinColumns={@ORM\JoinColumn(name="sortable_id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="group_id")} + * ) + * + * @Gedmo\SortableGroup + */ + #[ORM\ManyToMany(targetEntity: SortableGroup::class)] + #[ORM\JoinTable(name: 'sortable_sortable_groups')] + #[ORM\JoinColumn(name: 'sortable_id')] + #[ORM\InverseJoinColumn(name: 'group_id')] + #[Gedmo\SortableGroup] + private Collection $sortable_groups; + + public function __construct() + { + $this->sortable_groups = new ArrayCollection(); + } +} diff --git a/tests/Gedmo/Mapping/Fixture/SortableGroup.php b/tests/Gedmo/Mapping/Fixture/SortableGroup.php index 600892d1ff..ff5e8485b0 100644 --- a/tests/Gedmo/Mapping/Fixture/SortableGroup.php +++ b/tests/Gedmo/Mapping/Fixture/SortableGroup.php @@ -11,27 +11,34 @@ namespace Gedmo\Tests\Mapping\Fixture; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Table(name="test_sortable_groups") * @ORM\Entity + * @ORM\Table(name="test_sortable_groups") */ +#[ORM\Entity] +#[ORM\Table(name: 'test_sortable_groups')] class SortableGroup { /** - * @var int|null + * @var int * - * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] private $id; /** - * @var string|null + * @var string * - * @ORM\Column(length=64) + * @ORM\Column(type="string", length=64) */ + #[ORM\Column(type: Types::STRING, length: 64)] private $name; } diff --git a/tests/Gedmo/Mapping/Fixture/Uploadable.php b/tests/Gedmo/Mapping/Fixture/Uploadable.php new file mode 100644 index 0000000000..1a236718b1 --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/Uploadable.php @@ -0,0 +1,86 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture; + +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; +use Gedmo\Uploadable\Mapping\Validator; + +/** + * @ORM\Entity + * + * @Gedmo\Uploadable(allowOverwrite=true, appendNumber=true, path="/my/path", pathMethod="getPath", callback="callbackMethod", filenameGenerator="SHA1", maxSize="1500", allowedTypes="text/plain,text/css", disallowedTypes="video/jpeg,text/html") + */ +#[ORM\Entity] +#[Gedmo\Uploadable(allowOverwrite: true, appendNumber: true, path: '/my/path', pathMethod: 'getPath', callback: 'callbackMethod', filenameGenerator: Validator::FILENAME_GENERATOR_SHA1, maxSize: '1500', allowedTypes: 'text/plain,text/css', disallowedTypes: 'video/jpeg,text/html')] +class Uploadable +{ + /** + * @var int + * + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + private $id; + + /** + * @var string + * + * @ORM\Column(name="mime", type="string") + * + * @Gedmo\UploadableFileMimeType + */ + #[ORM\Column(name: 'mime', type: Types::STRING)] + #[Gedmo\UploadableFileMimeType] + private $mimeType; + + /** + * @var array + */ + private $fileInfo; + + /** + * @var float + * + * @ORM\Column(name="size", type="decimal") + * + * @Gedmo\UploadableFileSize + */ + #[ORM\Column(name: 'size', type: Types::DECIMAL)] + #[Gedmo\UploadableFileSize] + private $size; + + /** + * @var string + * + * @ORM\Column(name="path", type="string") + * + * @Gedmo\UploadableFilePath + */ + #[ORM\Column(name: 'path', type: Types::STRING)] + #[Gedmo\UploadableFilePath] + private $path; + + public function getPath(): string + { + return $this->path; + } + + public function callbackMethod(): void + { + } +} diff --git a/tests/Gedmo/Mapping/LoggableORMMappingTest.php b/tests/Gedmo/Mapping/LoggableORMMappingTest.php index 44a0a17ce0..d60c02aefe 100644 --- a/tests/Gedmo/Mapping/LoggableORMMappingTest.php +++ b/tests/Gedmo/Mapping/LoggableORMMappingTest.php @@ -18,14 +18,18 @@ use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Loggable\LoggableListener; use Gedmo\Mapping\ExtensionMetadataFactory; -use Gedmo\Tests\Mapping\Fixture\Category as AnnotatedCategory; +use Gedmo\Tests\Mapping\Fixture\Loggable as AnnotatedLoggable; use Gedmo\Tests\Mapping\Fixture\LoggableComposite as AnnotatedLoggableComposite; use Gedmo\Tests\Mapping\Fixture\LoggableCompositeRelation as AnnotatedLoggableCompositeRelation; +use Gedmo\Tests\Mapping\Fixture\LoggableWithEmbedded as AnnotatedLoggableWithEmbedded; +use Gedmo\Tests\Mapping\Fixture\Xml\Loggable as XmlLoggable; use Gedmo\Tests\Mapping\Fixture\Xml\LoggableComposite as XmlLoggableComposite; use Gedmo\Tests\Mapping\Fixture\Xml\LoggableCompositeRelation as XmlLoggableCompositeRelation; -use Gedmo\Tests\Mapping\Fixture\Yaml\Category as YamlCategory; +use Gedmo\Tests\Mapping\Fixture\Xml\LoggableWithEmbedded as XmlLoggableWithEmbedded; +use Gedmo\Tests\Mapping\Fixture\Yaml\Loggable as YamlLoggable; use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableComposite as YamlLoggableComposite; use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableCompositeRelation as YamlLoggableCompositeRelation; +use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableWithEmbedded as YamlLoggableWithEmbedded; /** * These are mapping tests for the loggable extension @@ -49,19 +53,21 @@ protected function setUp(): void /** * @return \Generator + * + * @note the XML fixture has a different mapping from the other configs, so it is tested separately */ public static function dataLoggableObject(): \Generator { if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { - yield 'Model with attributes' => [AnnotatedCategory::class]; + yield 'Model with attributes' => [AnnotatedLoggable::class]; } if (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedCategory::class]; + yield 'Model with annotations' => [AnnotatedLoggable::class]; } if (class_exists(YamlDriver::class)) { - yield 'Model with YAML mapping' => [YamlCategory::class]; + yield 'Model with YAML mapping' => [YamlLoggable::class]; } } @@ -77,10 +83,34 @@ public function testLoggableMapping(string $className): void $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Loggable'); $config = $this->cache->getItem($cacheId)->get(); + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); static::assertArrayHasKey('loggable', $config); static::assertTrue($config['loggable']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(1, $config['versioned']); + static::assertContains('title', $config['versioned']); + } + + public function testLoggableXmlMapping(): void + { + $className = XmlLoggable::class; + + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Loggable'); + $config = $this->cache->getItem($cacheId)->get(); + static::assertArrayHasKey('logEntryClass', $config); static::assertSame(LogEntry::class, $config['logEntryClass']); + static::assertArrayHasKey('loggable', $config); + static::assertTrue($config['loggable']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(2, $config['versioned']); + static::assertContains('title', $config['versioned']); + static::assertContains('status', $config['versioned']); } /** @@ -120,6 +150,12 @@ public function testLoggableCompositeMapping(string $className): void static::assertArrayHasKey('loggable', $config); static::assertTrue($config['loggable']); + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(1, $config['versioned']); + static::assertContains('title', $config['versioned']); } /** @@ -159,5 +195,97 @@ public function testLoggableCompositeRelationMapping(string $className): void static::assertArrayHasKey('loggable', $config); static::assertTrue($config['loggable']); + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(1, $config['versioned']); + static::assertContains('title', $config['versioned']); + } + + /* + * Each of the mapping drivers handles versioning embedded objects differently, so instead of using a single test case, + * these will be run as separate cases checking each driver's config appropriately. + */ + + /** + * @return \Generator + */ + public static function dataLoggableObjectWithEmbedded(): \Generator + { + if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + yield 'Model with attributes' => [AnnotatedLoggableWithEmbedded::class]; + } + + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedLoggableWithEmbedded::class]; + } + } + + /** + * @param class-string $className + * + * @dataProvider dataLoggableObjectWithEmbedded + */ + public function testLoggableAnnotatedWithEmbedded(string $className): void + { + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Loggable'); + $config = $this->cache->getItem($cacheId)->get(); + + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); + static::assertArrayHasKey('loggable', $config); + static::assertTrue($config['loggable']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(1, $config['versioned']); + static::assertContains('title', $config['versioned']); + } + + public function testLoggableXmlWithEmbedded(): void + { + $className = XmlLoggableWithEmbedded::class; + + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Loggable'); + $config = $this->cache->getItem($cacheId)->get(); + + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); + static::assertArrayHasKey('loggable', $config); + static::assertTrue($config['loggable']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(3, $config['versioned']); + static::assertContains('title', $config['versioned']); + static::assertContains('status', $config['versioned']); + static::assertContains('embedded', $config['versioned']); + } + + public function testLoggableYamlWithEmbedded(): void + { + if (!class_exists(YamlDriver::class)) { + static::markTestSkipped('Test case requires the deprecated YAML mapping driver from the ORM.'); + } + + $className = YamlLoggableWithEmbedded::class; + + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Loggable'); + $config = $this->cache->getItem($cacheId)->get(); + + static::assertArrayHasKey('logEntryClass', $config); + static::assertSame(LogEntry::class, $config['logEntryClass']); + static::assertArrayHasKey('loggable', $config); + static::assertTrue($config['loggable']); + + static::assertArrayHasKey('versioned', $config); + static::assertCount(2, $config['versioned']); + static::assertContains('title', $config['versioned']); + static::assertContains('embedded.subtitle', $config['versioned']); } } diff --git a/tests/Gedmo/Mapping/SluggableMappingTest.php b/tests/Gedmo/Mapping/SluggableMappingTest.php index 373c8841e8..b39e55de00 100644 --- a/tests/Gedmo/Mapping/SluggableMappingTest.php +++ b/tests/Gedmo/Mapping/SluggableMappingTest.php @@ -12,12 +12,15 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sluggable\Handler\RelativeSlugHandler; use Gedmo\Sluggable\Handler\TreeSlugHandler; use Gedmo\Sluggable\SluggableListener; -use Gedmo\Tests\Mapping\Fixture\Sluggable; +use Gedmo\Tests\Mapping\Fixture\Sluggable as AnnotatedSluggable; +use Gedmo\Tests\Mapping\Fixture\Xml\Sluggable as XmlSluggable; use Gedmo\Tests\Mapping\Fixture\Yaml\Category; /** @@ -27,18 +30,12 @@ */ final class SluggableMappingTest extends ORMMappingTestCase { - private const TEST_YAML_ENTITY_CLASS = Category::class; - private const SLUGGABLE = Sluggable::class; - private EntityManager $em; protected function setUp(): void { parent::setUp(); - $config = $this->getBasicConfiguration(); - $config->setMetadataDriverImpl($this->createChainedMappingDriver()); - $listener = new SluggableListener(); $listener->setCacheItemPool($this->cache); @@ -46,26 +43,42 @@ protected function setUp(): void $this->em->getEventManager()->addEventSubscriber($listener); } - public function testShouldBeAbleToMapSluggableUsingYamlDriver(): void + /** + * @return \Generator + */ + public static function dataSluggableObject(): \Generator { - if (!class_exists(YamlDriver::class)) { - static::markTestSkipped('Test requires deprecated ORM YAML mapping.'); + yield 'Model with XML mapping' => [XmlSluggable::class]; + + if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + yield 'Model with attributes' => [AnnotatedSluggable::class]; } + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedSluggable::class]; + } + } + + /** + * @param class-string $className + * + * @dataProvider dataSluggableObject + */ + public function testSluggableMapping(string $className): void + { // Force metadata class loading. - $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS); - $cacheId = ExtensionMetadataFactory::getCacheId( - self::TEST_YAML_ENTITY_CLASS, - 'Gedmo\Sluggable' - ); + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Sluggable'); $config = $this->cache->getItem($cacheId)->get(); static::assertArrayHasKey('slugs', $config); static::assertArrayHasKey('slug', $config['slugs']); static::assertSame('slug', $config['slugs']['slug']['slug']); static::assertArrayHasKey('fields', $config['slugs']['slug']); - static::assertCount(1, $config['slugs']['slug']['fields']); + static::assertCount(3, $config['slugs']['slug']['fields']); static::assertSame('title', $config['slugs']['slug']['fields'][0]); + static::assertSame('ean', $config['slugs']['slug']['fields'][1]); + static::assertSame('code', $config['slugs']['slug']['fields'][2]); static::assertArrayHasKey('style', $config['slugs']['slug']); static::assertSame('camel', $config['slugs']['slug']['style']); @@ -74,7 +87,7 @@ public function testShouldBeAbleToMapSluggableUsingYamlDriver(): void static::assertArrayHasKey('unique', $config['slugs']['slug']); static::assertTrue($config['slugs']['slug']['unique']); static::assertArrayHasKey('updatable', $config['slugs']['slug']); - static::assertTrue($config['slugs']['slug']['updatable']); + static::assertFalse($config['slugs']['slug']['updatable']); static::assertArrayHasKey('handlers', $config['slugs']['slug']); $handlers = $config['slugs']['slug']['handlers']; @@ -95,20 +108,39 @@ public function testShouldBeAbleToMapSluggableUsingYamlDriver(): void static::assertArrayHasKey('relationSlugField', $second); static::assertArrayHasKey('separator', $second); static::assertSame('parent', $second['relationField']); - static::assertSame('slug', $second['relationSlugField']); - static::assertSame('/', $second['separator']); + static::assertSame('test', $second['relationSlugField']); + static::assertSame('-', $second['separator']); } - public function testShouldBeAbleToMapSluggableUsingAnnotationDriver(): void + public function testSluggableYamlMapping(): void { + if (!class_exists(YamlDriver::class)) { + static::markTestSkipped('Test case requires the deprecated YAML mapping driver from the ORM.'); + } + + $className = Category::class; + // Force metadata class loading. - $this->em->getClassMetadata(self::SLUGGABLE); - $cacheId = ExtensionMetadataFactory::getCacheId( - self::SLUGGABLE, - 'Gedmo\Sluggable' - ); + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Sluggable'); $config = $this->cache->getItem($cacheId)->get(); + static::assertArrayHasKey('slugs', $config); + static::assertArrayHasKey('slug', $config['slugs']); + static::assertSame('slug', $config['slugs']['slug']['slug']); + static::assertArrayHasKey('fields', $config['slugs']['slug']); + static::assertCount(1, $config['slugs']['slug']['fields']); + static::assertSame('title', $config['slugs']['slug']['fields'][0]); + + static::assertArrayHasKey('style', $config['slugs']['slug']); + static::assertSame('camel', $config['slugs']['slug']['style']); + static::assertArrayHasKey('separator', $config['slugs']['slug']); + static::assertSame('_', $config['slugs']['slug']['separator']); + static::assertArrayHasKey('unique', $config['slugs']['slug']); + static::assertTrue($config['slugs']['slug']['unique']); + static::assertArrayHasKey('updatable', $config['slugs']['slug']); + static::assertTrue($config['slugs']['slug']['updatable']); + static::assertArrayHasKey('handlers', $config['slugs']['slug']); $handlers = $config['slugs']['slug']['handlers']; static::assertCount(2, $handlers); @@ -127,7 +159,7 @@ public function testShouldBeAbleToMapSluggableUsingAnnotationDriver(): void static::assertArrayHasKey('relationField', $second); static::assertArrayHasKey('relationSlugField', $second); static::assertArrayHasKey('separator', $second); - static::assertSame('user', $second['relationField']); + static::assertSame('parent', $second['relationField']); static::assertSame('slug', $second['relationSlugField']); static::assertSame('/', $second['separator']); } diff --git a/tests/Gedmo/Mapping/SortableMappingTest.php b/tests/Gedmo/Mapping/SortableMappingTest.php index 7cdb16d084..d81ea50924 100644 --- a/tests/Gedmo/Mapping/SortableMappingTest.php +++ b/tests/Gedmo/Mapping/SortableMappingTest.php @@ -11,55 +11,69 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; +use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sortable\SortableListener; -use Gedmo\Tests\Mapping\Fixture\SortableGroup; -use Gedmo\Tests\Mapping\Fixture\Yaml\Sortable; -use Gedmo\Tests\Tool\BaseTestCaseOM; +use Gedmo\Tests\Mapping\Fixture\Sortable as AnnotatedSortable; +use Gedmo\Tests\Mapping\Fixture\Xml\Sortable as XmlSortable; +use Gedmo\Tests\Mapping\Fixture\Yaml\Sortable as YamlSortable; /** * These are mapping tests for sortable extension * * @author Lukas Botsch */ -final class SortableMappingTest extends BaseTestCaseOM +final class SortableMappingTest extends ORMMappingTestCase { private EntityManager $em; - private SortableListener $sortable; - protected function setUp(): void { parent::setUp(); - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + $listener = new SortableListener(); + $listener->setCacheItemPool($this->cache); + + $this->em = $this->getBasicEntityManager(); + $this->em->getEventManager()->addEventSubscriber($listener); + } - $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml'); + /** + * @return \Generator + * + * @note the XML fixture has a different mapping from the other configs, so it is tested separately + */ + public static function dataSortableObject(): \Generator + { + yield 'Model with XML mapping' => [XmlSortable::class]; - $chain = new MappingDriverChain(); - $chain->addDriver($yamlDriver, 'Gedmo\Tests\Mapping\Fixture\Yaml'); - $chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); + if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + yield 'Model with attributes' => [AnnotatedSortable::class]; + } - $this->sortable = new SortableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->sortable); + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedSortable::class]; + } - $this->em = $this->getDefaultMockSqliteEntityManager([ - Sortable::class, - SortableGroup::class, - ], $chain); + if (class_exists(YamlDriver::class)) { + yield 'Model with YAML mapping' => [YamlSortable::class]; + } } - public function testYamlMapping(): void + /** + * @param class-string $className + * + * @dataProvider dataSortableObject + */ + public function testSortableMapping(string $className): void { - $meta = $this->em->getClassMetadata(Sortable::class); - $config = $this->sortable->getConfiguration($this->em, $meta->getName()); + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Sortable'); + $config = $this->cache->getItem($cacheId)->get(); static::assertArrayHasKey('position', $config); static::assertSame('position', $config['position']); diff --git a/tests/Gedmo/Mapping/TimestampableMappingTest.php b/tests/Gedmo/Mapping/TimestampableMappingTest.php index 65c4f8180b..c547215ede 100644 --- a/tests/Gedmo/Mapping/TimestampableMappingTest.php +++ b/tests/Gedmo/Mapping/TimestampableMappingTest.php @@ -11,13 +11,14 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\EventManager; -use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Mapping\ExtensionMetadataFactory; -use Gedmo\Tests\Mapping\Fixture\Yaml\Category; +use Gedmo\Tests\Mapping\Fixture\Category as AnnotatedCategory; +use Gedmo\Tests\Mapping\Fixture\Xml\Timestampable; +use Gedmo\Tests\Mapping\Fixture\Yaml\Category as YamlCategory; use Gedmo\Timestampable\TimestampableListener; /** @@ -27,45 +28,51 @@ */ final class TimestampableMappingTest extends ORMMappingTestCase { - private const TEST_YAML_ENTITY_CLASS = Category::class; - private EntityManager $em; protected function setUp(): void { parent::setUp(); - $config = $this->getBasicConfiguration(); - - $chain = new MappingDriverChain(); + $listener = new TimestampableListener(); + $listener->setCacheItemPool($this->cache); - // TODO - The ORM's YAML mapping is deprecated and removed in 3.0 - $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); + $this->em = $this->getBasicEntityManager(); + $this->em->getEventManager()->addEventSubscriber($listener); + } - $config->setMetadataDriverImpl($chain); + /** + * @return \Generator + * + * @note the XML fixture has a different mapping from the other configs, so it is tested separately + */ + public static function dataTimestampableObject(): \Generator + { + if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + yield 'Model with attributes' => [AnnotatedCategory::class]; + } - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedCategory::class]; + } - $evm = new EventManager(); - $listener = new TimestampableListener(); - $listener->setCacheItemPool($this->cache); - $evm->addEventSubscriber($listener); - $connection = DriverManager::getConnection($conn, $config); - $this->em = new EntityManager($connection, $config, $evm); + if (class_exists(YamlDriver::class)) { + yield 'Model with YAML mapping' => [YamlCategory::class]; + } } - public function testYamlMapping(): void + /** + * @param class-string $className + * + * @dataProvider dataTimestampableObject + */ + public function testTimestampableMapping(string $className): void { // Force metadata class loading. - $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS); - $cacheId = ExtensionMetadataFactory::getCacheId( - self::TEST_YAML_ENTITY_CLASS, - 'Gedmo\Timestampable' - ); + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Timestampable'); $config = $this->cache->getItem($cacheId)->get(); + static::assertArrayHasKey('create', $config); static::assertSame('created', $config['create'][0]); static::assertArrayHasKey('update', $config); @@ -77,4 +84,25 @@ public function testYamlMapping(): void static::assertSame('title', $onChange['trackedField']); static::assertSame('Test', $onChange['value']); } + + public function testTimestampableXmlMapping(): void + { + $className = Timestampable::class; + + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Timestampable'); + $config = $this->cache->getItem($cacheId)->get(); + + static::assertArrayHasKey('create', $config); + static::assertSame('created', $config['create'][0]); + static::assertArrayHasKey('update', $config); + static::assertSame('updated', $config['update'][0]); + static::assertArrayHasKey('change', $config); + $onChange = $config['change'][0]; + + static::assertSame('published', $onChange['field']); + static::assertSame('status.title', $onChange['trackedField']); + static::assertSame('Published', $onChange['value']); + } } diff --git a/tests/Gedmo/Mapping/UploadableMappingTest.php b/tests/Gedmo/Mapping/UploadableMappingTest.php index fb991bff5c..79624146b8 100644 --- a/tests/Gedmo/Mapping/UploadableMappingTest.php +++ b/tests/Gedmo/Mapping/UploadableMappingTest.php @@ -11,14 +11,14 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Tests\Mapping\Fixture\Yaml\Uploadable; -use Gedmo\Tests\Tool\BaseTestCaseOM; +use Gedmo\Mapping\ExtensionMetadataFactory; +use Gedmo\Tests\Mapping\Fixture\Uploadable as AnnotatedUploadable; +use Gedmo\Tests\Mapping\Fixture\Xml\Uploadable as XmlUploadable; +use Gedmo\Tests\Mapping\Fixture\Yaml\Uploadable as YamlUploadable; use Gedmo\Uploadable\Mapping\Validator; use Gedmo\Uploadable\UploadableListener; @@ -28,40 +28,55 @@ * @author Gustavo Falco * @author Gediminas Morkevicius */ -final class UploadableMappingTest extends BaseTestCaseOM +final class UploadableMappingTest extends ORMMappingTestCase { private EntityManager $em; - private UploadableListener $listener; - protected function setUp(): void { parent::setUp(); + // TODO - This should be reset to default (true) after each test case Validator::$enableMimeTypesConfigException = false; - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + $listener = new UploadableListener(); + $listener->setCacheItemPool($this->cache); + + $this->em = $this->getBasicEntityManager(); + $this->em->getEventManager()->addEventSubscriber($listener); + } - $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml'); + /** + * @return \Generator + */ + public static function dataUploadableObject(): \Generator + { + yield 'Model with XML mapping' => [XmlUploadable::class]; - $chain = new MappingDriverChain(); - $chain->addDriver($yamlDriver, 'Gedmo\Tests\Mapping\Fixture\Yaml'); - $chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); + if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + yield 'Model with attributes' => [AnnotatedUploadable::class]; + } - $this->listener = new UploadableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->listener); + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedUploadable::class]; + } - $this->em = $this->getDefaultMockSqliteEntityManager([ - Uploadable::class, - ], $chain); + if (class_exists(YamlDriver::class)) { + yield 'Model with YAML mapping' => [YamlUploadable::class]; + } } - public function testYamlMapping(): void + /** + * @param class-string $className + * + * @dataProvider dataUploadableObject + */ + public function testUploadableMapping(string $className): void { - $meta = $this->em->getClassMetadata(Uploadable::class); - $config = $this->listener->getConfiguration($this->em, $meta->getName()); + // Force metadata class loading. + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Uploadable'); + $config = $this->cache->getItem($cacheId)->get(); static::assertTrue($config['uploadable']); static::assertTrue($config['allowOverwrite']); @@ -72,7 +87,7 @@ public function testYamlMapping(): void static::assertSame('path', $config['filePathField']); static::assertSame('size', $config['fileSizeField']); static::assertSame('callbackMethod', $config['callback']); - static::assertSame('SHA1', $config['filenameGenerator']); + static::assertSame(Validator::FILENAME_GENERATOR_SHA1, $config['filenameGenerator']); static::assertSame(1500.0, $config['maxSize']); static::assertContains('text/plain', $config['allowedTypes']); static::assertContains('text/css', $config['allowedTypes']); diff --git a/tests/Gedmo/Mapping/Xml/LoggableMappingTest.php b/tests/Gedmo/Mapping/Xml/LoggableMappingTest.php deleted file mode 100644 index e61ddf5ce9..0000000000 --- a/tests/Gedmo/Mapping/Xml/LoggableMappingTest.php +++ /dev/null @@ -1,132 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Loggable\Entity\LogEntry; -use Gedmo\Loggable\LoggableListener; -use Gedmo\Tests\Mapping\Fixture\Xml\Embedded; -use Gedmo\Tests\Mapping\Fixture\Xml\Loggable; -use Gedmo\Tests\Mapping\Fixture\Xml\LoggableComposite; -use Gedmo\Tests\Mapping\Fixture\Xml\LoggableCompositeRelation; -use Gedmo\Tests\Mapping\Fixture\Xml\LoggableWithEmbedded; -use Gedmo\Tests\Mapping\Fixture\Xml\Status; -use Gedmo\Tests\Tool\BaseTestCaseOM; - -/** - * These are mapping extension tests - * - * @author Gediminas Morkevicius - */ -final class LoggableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - /** - * @phpstan-var LoggableListener - */ - private LoggableListener $loggable; - - protected function setUp(): void - { - parent::setUp(); - - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($annotationDriver, 'Gedmo\Loggable'); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - - $this->loggable = new LoggableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->loggable); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - LogEntry::class, - Loggable::class, - LoggableWithEmbedded::class, - Embedded::class, - Status::class, - ], $chain); - } - - public function testLoggableMetadata(): void - { - $meta = $this->em->getClassMetadata(Loggable::class); - $config = $this->loggable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(2, $config['versioned']); - static::assertContains('title', $config['versioned']); - static::assertContains('status', $config['versioned']); - } - - public function testLoggableCompositeMetadata(): void - { - $meta = $this->em->getClassMetadata(LoggableComposite::class); - $config = $this->loggable->getConfiguration($this->em, $meta->name); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(1, $config['versioned']); - static::assertContains('title', $config['versioned']); - } - - public function testLoggableCompositeRelationMetadata(): void - { - $meta = $this->em->getClassMetadata(LoggableCompositeRelation::class); - $config = $this->loggable->getConfiguration($this->em, $meta->name); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(1, $config['versioned']); - static::assertContains('title', $config['versioned']); - } - - public function testLoggableMetadataWithEmbedded(): void - { - $meta = $this->em->getClassMetadata(LoggableWithEmbedded::class); - $config = $this->loggable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(3, $config['versioned']); - static::assertContains('title', $config['versioned']); - static::assertContains('status', $config['versioned']); - static::assertContains('embedded', $config['versioned']); - } -} diff --git a/tests/Gedmo/Mapping/Xml/SluggableMappingTest.php b/tests/Gedmo/Mapping/Xml/SluggableMappingTest.php deleted file mode 100644 index f04a39aca8..0000000000 --- a/tests/Gedmo/Mapping/Xml/SluggableMappingTest.php +++ /dev/null @@ -1,109 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\EventManager; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Sluggable\Handler\RelativeSlugHandler; -use Gedmo\Sluggable\Handler\TreeSlugHandler; -use Gedmo\Sluggable\SluggableListener; -use Gedmo\Tests\Mapping\Fixture\Xml\Sluggable; -use Gedmo\Tests\Tool\BaseTestCaseORM; - -/** - * These are mapping extension tests - * - * @author Gediminas Morkevicius - */ -final class SluggableMappingTest extends BaseTestCaseORM -{ - private SluggableListener $sluggable; - - protected function setUp(): void - { - parent::setUp(); - - $this->sluggable = new SluggableListener(); - $evm = new EventManager(); - $evm->addEventSubscriber($this->sluggable); - - $this->getDefaultMockSqliteEntityManager($evm); - } - - public function testShouldBeAbleToMapSluggableMetadata(): void - { - $meta = $this->em->getClassMetadata(Sluggable::class); - $config = $this->sluggable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('slug', $config['slugs']); - static::assertCount(1, $config['slugs']); - $config = $config['slugs']['slug']; - - static::assertSame('slug', $config['slug']); - static::assertArrayHasKey('style', $config); - static::assertSame('camel', $config['style']); - static::assertArrayHasKey('updatable', $config); - static::assertFalse($config['updatable']); - static::assertArrayHasKey('unique', $config); - static::assertTrue($config['unique']); - static::assertArrayHasKey('separator', $config); - static::assertSame('_', $config['separator']); - - static::assertArrayHasKey('fields', $config); - static::assertCount(3, $config['fields']); - $fields = $config['fields']; - - static::assertSame('title', $fields[0]); - static::assertSame('ean', $fields[1]); - static::assertSame('code', $fields[2]); - - static::assertArrayHasKey('handlers', $config); - static::assertCount(2, $config['handlers']); - $handlers = $config['handlers']; - - static::assertArrayHasKey(TreeSlugHandler::class, $handlers); - static::assertArrayHasKey(RelativeSlugHandler::class, $handlers); - - $first = $handlers[TreeSlugHandler::class]; - static::assertCount(2, $first); - static::assertArrayHasKey('parentRelationField', $first); - static::assertArrayHasKey('separator', $first); - static::assertSame('parent', $first['parentRelationField']); - static::assertSame('/', $first['separator']); - - $second = $handlers[RelativeSlugHandler::class]; - static::assertCount(3, $second); - static::assertArrayHasKey('relationField', $second); - static::assertArrayHasKey('relationSlugField', $second); - static::assertArrayHasKey('separator', $second); - static::assertSame('parent', $second['relationField']); - static::assertSame('test', $second['relationSlugField']); - static::assertSame('-', $second['separator']); - } - - protected function getUsedEntityFixtures(): array - { - return [Sluggable::class]; - } - - protected function getMetadataDriverImplementation(): MappingDriver - { - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - - return $chain; - } -} diff --git a/tests/Gedmo/Mapping/Xml/SoftDeleteableMappingTest.php b/tests/Gedmo/Mapping/Xml/SoftDeleteableMappingTest.php deleted file mode 100644 index d65e9af48a..0000000000 --- a/tests/Gedmo/Mapping/Xml/SoftDeleteableMappingTest.php +++ /dev/null @@ -1,71 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\SoftDeleteable\SoftDeleteableListener; -use Gedmo\Tests\Mapping\Fixture\Xml\SoftDeleteable; -use Gedmo\Tests\Tool\BaseTestCaseOM; - -/** - * These are mapping tests for SoftDeleteable extension - * - * @author Gustavo Falco - * @author Gediminas Morkevicius - */ -final class SoftDeleteableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - private SoftDeleteableListener $softDeleteable; - - protected function setUp(): void - { - parent::setUp(); - - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - $chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); - - $this->softDeleteable = new SoftDeleteableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->softDeleteable); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - SoftDeleteable::class, - \Gedmo\Tests\Mapping\Fixture\SoftDeleteable::class, - ], $chain); - } - - public function testMetadata(): void - { - $meta = $this->em->getClassMetadata(SoftDeleteable::class); - $config = $this->softDeleteable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('softDeleteable', $config); - static::assertTrue($config['softDeleteable']); - static::assertArrayHasKey('timeAware', $config); - static::assertFalse($config['timeAware']); - static::assertArrayHasKey('fieldName', $config); - static::assertSame('deletedAt', $config['fieldName']); - } -} diff --git a/tests/Gedmo/Mapping/Xml/SortableMappingTest.php b/tests/Gedmo/Mapping/Xml/SortableMappingTest.php deleted file mode 100644 index 745372478c..0000000000 --- a/tests/Gedmo/Mapping/Xml/SortableMappingTest.php +++ /dev/null @@ -1,72 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Sortable\SortableListener; -use Gedmo\Tests\Mapping\Fixture\SortableGroup; -use Gedmo\Tests\Mapping\Fixture\Xml\Sortable; -use Gedmo\Tests\Tool\BaseTestCaseOM; - -/** - * These are mapping extension tests - * - * @author Lukas Botsch - */ -final class SortableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - private SortableListener $sortable; - - protected function setUp(): void - { - parent::setUp(); - - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - $chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); - - $this->sortable = new SortableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->sortable); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - Sortable::class, - SortableGroup::class, - ], $chain); - } - - public function testSluggableMetadata(): void - { - $meta = $this->em->getClassMetadata(Sortable::class); - $config = $this->sortable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('position', $config); - static::assertSame('position', $config['position']); - static::assertArrayHasKey('groups', $config); - static::assertCount(3, $config['groups']); - static::assertSame('grouping', $config['groups'][0]); - static::assertSame('sortable_group', $config['groups'][1]); - static::assertSame('sortable_groups', $config['groups'][2]); - } -} diff --git a/tests/Gedmo/Mapping/Xml/TimestampableMappingTest.php b/tests/Gedmo/Mapping/Xml/TimestampableMappingTest.php deleted file mode 100644 index f6f1511fd2..0000000000 --- a/tests/Gedmo/Mapping/Xml/TimestampableMappingTest.php +++ /dev/null @@ -1,69 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Tests\Mapping\Fixture\Xml\Status; -use Gedmo\Tests\Mapping\Fixture\Xml\Timestampable; -use Gedmo\Tests\Tool\BaseTestCaseOM; -use Gedmo\Timestampable\TimestampableListener; - -/** - * These are mapping extension tests - * - * @author Gediminas Morkevicius - */ -final class TimestampableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - private TimestampableListener $timestampable; - - protected function setUp(): void - { - parent::setUp(); - - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - - $this->timestampable = new TimestampableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->timestampable); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - Timestampable::class, - Status::class, - ], $chain); - } - - public function testTimestampableMetadata(): void - { - $meta = $this->em->getClassMetadata(Timestampable::class); - $config = $this->timestampable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('create', $config); - static::assertSame('created', $config['create'][0]); - static::assertArrayHasKey('update', $config); - static::assertSame('updated', $config['update'][0]); - static::assertArrayHasKey('change', $config); - $onChange = $config['change'][0]; - - static::assertSame('published', $onChange['field']); - static::assertSame('status.title', $onChange['trackedField']); - static::assertSame('Published', $onChange['value']); - } -} diff --git a/tests/Gedmo/Mapping/Xml/UploadableMappingTest.php b/tests/Gedmo/Mapping/Xml/UploadableMappingTest.php deleted file mode 100644 index f1ecaeb50f..0000000000 --- a/tests/Gedmo/Mapping/Xml/UploadableMappingTest.php +++ /dev/null @@ -1,82 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Xml; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\XmlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Tests\Mapping\Fixture\Xml\Uploadable; -use Gedmo\Tests\Tool\BaseTestCaseOM; -use Gedmo\Uploadable\Mapping\Validator; -use Gedmo\Uploadable\UploadableListener; - -/** - * These are mapping tests for Uploadable extension - * - * @author Gustavo Falco - * @author Gediminas Morkevicius - */ -final class UploadableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - private UploadableListener $listener; - - protected function setUp(): void - { - parent::setUp(); - - Validator::$enableMimeTypesConfigException = false; - - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); - $chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); - - $this->listener = new UploadableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->listener); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - Uploadable::class, - ], $chain); - } - - public function testMetadata(): void - { - $meta = $this->em->getClassMetadata(Uploadable::class); - $config = $this->listener->getConfiguration($this->em, $meta->getName()); - - static::assertTrue($config['uploadable']); - static::assertTrue($config['allowOverwrite']); - static::assertTrue($config['appendNumber']); - static::assertSame('/my/path', $config['path']); - static::assertSame('getPath', $config['pathMethod']); - static::assertSame('mimeType', $config['fileMimeTypeField']); - static::assertSame('path', $config['filePathField']); - static::assertSame('size', $config['fileSizeField']); - static::assertSame('callbackMethod', $config['callback']); - static::assertSame('SHA1', $config['filenameGenerator']); - static::assertSame(1500.0, $config['maxSize']); - static::assertContains('text/plain', $config['allowedTypes']); - static::assertContains('text/css', $config['allowedTypes']); - static::assertContains('video/jpeg', $config['disallowedTypes']); - static::assertContains('text/html', $config['disallowedTypes']); - } -} diff --git a/tests/Gedmo/Mapping/Yaml/LoggableMappingTest.php b/tests/Gedmo/Mapping/Yaml/LoggableMappingTest.php deleted file mode 100644 index a70538cb8e..0000000000 --- a/tests/Gedmo/Mapping/Yaml/LoggableMappingTest.php +++ /dev/null @@ -1,111 +0,0 @@ - http://www.gediminasm.org - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Gedmo\Tests\Mapping\Yaml; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Loggable\Entity\LogEntry; -use Gedmo\Loggable\LoggableListener; -use Gedmo\Tests\Mapping\Fixture\Yaml\Embedded; -use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableComposite; -use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableCompositeRelation; -use Gedmo\Tests\Mapping\Fixture\Yaml\LoggableWithEmbedded; -use Gedmo\Tests\Tool\BaseTestCaseOM; - -/** - * These are mapping extension tests - * - * @author Gediminas Morkevicius - */ -final class LoggableMappingTest extends BaseTestCaseOM -{ - private EntityManager $em; - - /** - * @phpstan-var LoggableListener - */ - private LoggableListener $loggable; - - protected function setUp(): void - { - parent::setUp(); - - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $yamlDriver = new YamlDriver(__DIR__.'/../Driver/Yaml'); - - $chain = new MappingDriverChain(); - $chain->addDriver($annotationDriver, 'Gedmo\Loggable'); - $chain->addDriver($yamlDriver, 'Gedmo\Tests\Mapping\Fixture\Yaml'); - - $this->loggable = new LoggableListener(); - $this->evm = new EventManager(); - $this->evm->addEventSubscriber($this->loggable); - - $this->em = $this->getDefaultMockSqliteEntityManager([ - LogEntry::class, - LoggableWithEmbedded::class, - Embedded::class, - ], $chain); - } - - public function testLoggableCompositeMetadata(): void - { - $meta = $this->em->getClassMetadata(LoggableComposite::class); - $config = $this->loggable->getConfiguration($this->em, $meta->name); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(1, $config['versioned']); - static::assertContains('title', $config['versioned']); - } - - public function testLoggableCompositeRelationMetadata(): void - { - $meta = $this->em->getClassMetadata(LoggableCompositeRelation::class); - $config = $this->loggable->getConfiguration($this->em, $meta->name); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(1, $config['versioned']); - static::assertContains('title', $config['versioned']); - } - - public function testLoggableMetadataWithEmbedded(): void - { - $meta = $this->em->getClassMetadata(LoggableWithEmbedded::class); - $config = $this->loggable->getConfiguration($this->em, $meta->getName()); - - static::assertArrayHasKey('logEntryClass', $config); - static::assertSame(LogEntry::class, $config['logEntryClass']); - static::assertArrayHasKey('loggable', $config); - static::assertTrue($config['loggable']); - - static::assertArrayHasKey('versioned', $config); - static::assertCount(2, $config['versioned']); - static::assertContains('title', $config['versioned']); - static::assertContains('embedded.subtitle', $config['versioned']); - } -}