Skip to content

Commit

Permalink
TASK: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Feb 22, 2024
1 parent b780ea3 commit 3b578c3
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions Tests/Functional/Domain/Model/AssetCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface;
use Flowpack\Media\Ui\Service\AssetCollectionService;
use Flowpack\Media\Ui\Tests\Functional\AbstractTest;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Media\Domain\Model\AssetCollection;
Expand All @@ -31,6 +32,11 @@ class AssetCollectionTest extends AbstractTest
*/
protected $assetCollectionRepository;

/**
* @var AssetCollectionService
*/
protected $assetCollectionService;

public function setUp(): void
{
parent::setUp();
Expand All @@ -39,6 +45,7 @@ public function setUp(): void
}

$this->assetCollectionRepository = $this->objectManager->get(AssetCollectionRepository::class);
$this->assetCollectionService = $this->objectManager->get(AssetCollectionService::class);
}

/**
Expand Down Expand Up @@ -175,4 +182,89 @@ public function hasParentReturnsTrueIfParentIsSet(): void
self::assertTrue($persistedChild->hasParent());
self::assertFalse($persistedParent->hasParent());
}

/**
* @test
*/
public function newCollectionHasPathBasedOnTitle(): void
{
$collection = new AssetCollection('My Collection');
$this->assetCollectionRepository->add($collection);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedCollection = $this->assetCollectionRepository->findOneByTitle('My Collection');
self::assertEquals('/my-collection', $persistedCollection->getPath());
}

/**
* @test
*/
public function updatingTitleUpdatesPathOfCollection(): void
{
$collection = new AssetCollection('My Collection');
$this->assetCollectionRepository->add($collection);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedCollection = $this->assetCollectionRepository->findOneByTitle('My Collection');
$persistedCollection->setTitle('New Title');
$this->assetCollectionRepository->update($persistedCollection);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedCollection = $this->assetCollectionRepository->findOneByTitle('New Title');
self::assertEquals('/new-title', $persistedCollection->getPath());
}

/**
* @test
*/
public function pathOfSubCollectionContainsPathOfParentCollection(): void
{
$parent = new AssetCollection('Parent');
$child = new AssetCollection('Child');
$child->setParent($parent);

$this->assetCollectionRepository->add($parent);
$this->assetCollectionRepository->add($child);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedParent = $this->assetCollectionRepository->findOneByTitle('Parent');
$persistedChild = $this->assetCollectionRepository->findOneByTitle('Child');

self::assertEquals('/parent', $persistedParent->getPath());
self::assertEquals('/parent/child', $persistedChild->getPath());
}

/**
* @test
*/
public function pathOfSubCollectionUpdatesWhenParentIsRenamed(): void
{
$parent = new AssetCollection('Parent');
$child = new AssetCollection('Child');
$child->setParent($parent);

$this->assetCollectionRepository->add($parent);
$this->assetCollectionRepository->add($child);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedParent = $this->assetCollectionRepository->findOneByTitle('Parent');

$persistedParent->setTitle('New Parent Title');
$this->assetCollectionService->updatePathForNestedAssetCollections($persistedParent);

$this->assetCollectionRepository->update($persistedParent);
$this->persistenceManager->persistAll();
$this->persistenceManager->clearState();

$persistedParent = $this->assetCollectionRepository->findOneByTitle('New Parent Title');
$persistedChild = $this->assetCollectionRepository->findOneByTitle('Child');

self::assertEquals('/new-parent-title', $persistedParent->getPath());
self::assertEquals('/new-parent-title/child', $persistedChild->getPath());
}
}

0 comments on commit 3b578c3

Please sign in to comment.