2021-02-03 17:20:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Model;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2021-02-03 17:20:01 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Model\Entity;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
|
|
|
|
|
|
|
class EntityCollectionTest extends TestCase
|
|
|
|
{
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-03 17:20:01 +01:00
|
|
|
public function canBeCreated(): void
|
|
|
|
{
|
|
|
|
$subject = new EntityCollection();
|
|
|
|
|
|
|
|
self::assertInstanceOf(EntityCollection::class, $subject);
|
|
|
|
}
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-03 17:20:01 +01:00
|
|
|
public function returnsEmptyArrayAsDefaultEntities(): void
|
|
|
|
{
|
|
|
|
$subject = new EntityCollection();
|
|
|
|
|
|
|
|
self::assertSame([], $subject->getEntities());
|
|
|
|
}
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-03 17:20:01 +01:00
|
|
|
public function returnsFirstEntityForDefaultLanguage(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation = $this->createStub(Entity::class);
|
|
|
|
$entityWithTranslation->method('isForDefaultLanguage')->willReturn(false);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithDefaultLanguage = $this->createStub(Entity::class);
|
|
|
|
$entityWithDefaultLanguage->method('isForDefaultLanguage')->willReturn(true);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
$subject = new EntityCollection();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->add($entityWithTranslation);
|
|
|
|
$subject->add($entityWithDefaultLanguage);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
self::assertSame(
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithDefaultLanguage,
|
2021-02-03 17:20:01 +01:00
|
|
|
$subject->getDefaultLanguageEntity()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-03 17:20:01 +01:00
|
|
|
public function returnsNullIfNoEntityForDefaultLanguageExists(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation = $this->createStub(Entity::class);
|
|
|
|
$entityWithTranslation->method('isForDefaultLanguage')->willReturn(false);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
$subject = new EntityCollection();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->add($entityWithTranslation);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
2021-04-13 15:24:33 +02:00
|
|
|
self::assertNull(
|
2021-02-03 17:20:01 +01:00
|
|
|
$subject->getDefaultLanguageEntity()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-16 17:12:47 +01:00
|
|
|
public function returnsEntitiesToTranslate(): void
|
2021-02-03 17:20:01 +01:00
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation = $this->createStub(Entity::class);
|
|
|
|
$entityWithTranslation->method('isTranslation')->willReturn(true);
|
|
|
|
$entityWithTranslation->method('exists')->willReturn(false);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
$subject = new EntityCollection();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->add($entityWithTranslation);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
[
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation,
|
2021-02-03 17:20:01 +01:00
|
|
|
],
|
2021-02-16 17:12:47 +01:00
|
|
|
$subject->getEntitiesToTranslate()
|
2021-02-03 17:20:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-05 09:43:55 +01:00
|
|
|
#[Test]
|
2021-02-16 17:12:47 +01:00
|
|
|
public function returnsExistingEntities(): void
|
2021-02-03 17:20:01 +01:00
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation = $this->createStub(Entity::class);
|
|
|
|
$entityWithTranslation->method('exists')->willReturn(true);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
$subject = new EntityCollection();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->add($entityWithTranslation);
|
2021-02-03 17:20:01 +01:00
|
|
|
|
|
|
|
self::assertSame(
|
2021-02-16 17:12:47 +01:00
|
|
|
[
|
2022-09-13 09:05:47 +02:00
|
|
|
$entityWithTranslation,
|
2021-02-16 17:12:47 +01:00
|
|
|
],
|
|
|
|
$subject->getExistingEntities()
|
2021-02-03 17:20:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|