diff --git a/src/Entity/Event.php b/src/Entity/Event.php index aa68445..060dc54 100644 --- a/src/Entity/Event.php +++ b/src/Entity/Event.php @@ -136,6 +136,35 @@ public function setLocation(?string $location): self return $this; } + public function getImage(): ?MediaInterface + { + return $this->image; + } + + /** + * @return array|null + * + * @Serializer\VirtualProperty + * @Serializer\SerializedName("image") + */ + public function getImageData(): ?array + { + if (!$this->image) { + return null; + } + + return [ + 'id' => $this->image->getId(), + ]; + } + + public function setImage(?MediaInterface $image): self + { + $this->image = $image; + + return $this; + } + /** * @Serializer\VirtualProperty(name="title") */ @@ -247,31 +276,4 @@ protected function createTranslation(string $locale): EventTranslation return $translation; } - - public function getImage(): ?MediaInterface - { - return $this->image; - } - - /** - * @return array|null - * - * @Serializer\VirtualProperty - * @Serializer\SerializedName("image") - */ - public function getImageData(): ?array - { - if (!$this->image) { - return null; - } - - return [ - 'id' => $this->image->getId(), - ]; - } - - public function setImage(?MediaInterface $image): void - { - $this->image = $image; - } } diff --git a/tests/Unit/Entity/EventTest.php b/tests/Unit/Entity/EventTest.php index a956e4b..d61d521 100644 --- a/tests/Unit/Entity/EventTest.php +++ b/tests/Unit/Entity/EventTest.php @@ -7,6 +7,7 @@ use App\Entity\Event; use App\Entity\EventTranslation; use PHPUnit\Framework\TestCase; +use Sulu\Bundle\MediaBundle\Entity\MediaInterface; class EventTest extends TestCase { @@ -28,13 +29,6 @@ public function testEnabled(): void $this->assertTrue($this->event->isEnabled()); } - public function testLocale(): void - { - $this->assertSame('de', $this->event->getLocale()); - $this->assertSame($this->event, $this->event->setLocale('en')); - $this->assertSame('en', $this->event->getLocale()); - } - public function testStartDate(): void { $now = new \DateTimeImmutable(); @@ -55,6 +49,25 @@ public function testEndDate(): void $this->assertSame($now, $this->event->getEndDate()); } + public function testLocation(): void + { + $this->assertNull($this->event->getLocation()); + $this->assertSame($this->event, $this->event->setLocation('Amsterdam')); + $this->assertSame('Amsterdam', $this->event->getLocation()); + } + + public function testImage(): void + { + $image = $this->prophesize(MediaInterface::class); + $image->getId()->willReturn(1234); + + $this->assertNull($this->event->getImage()); + $this->assertNull($this->event->getImageData()); + $this->assertSame($this->event, $this->event->setImage($image->reveal())); + $this->assertSame($image->reveal(), $this->event->getImage()); + $this->assertSame(['id' => 1234], $this->event->getImageData()); + } + public function testTitle(): void { $this->assertNull($this->event->getTitle()); @@ -87,4 +100,11 @@ public function testDescription(): void $this->assertSame('de', $this->event->getTranslations()['de']->getLocale()); $this->assertSame('Sulu is awesome', $this->event->getTranslations()['de']->getDescription()); } + + public function testLocale(): void + { + $this->assertSame('de', $this->event->getLocale()); + $this->assertSame($this->event, $this->event->setLocale('en')); + $this->assertSame('en', $this->event->getLocale()); + } }