69 lines
2.6 KiB
PHP
69 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Test\Unit\Model;
|
|
|
|
use Esun\MultiLocaleTranslation\Model\BlogPostTranslationApplier;
|
|
use Esun\MultiLocaleTranslation\Model\CmsTranslationRepository;
|
|
use Magento\Framework\App\State;
|
|
use Magento\Store\Api\Data\StoreInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use Mageplaza\Blog\Model\Post;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BlogPostTranslationApplierTest extends TestCase
|
|
{
|
|
public function testAppliesCurrentStoreTranslationToPost(): void
|
|
{
|
|
$repository = $this->createMock(CmsTranslationRepository::class);
|
|
$repository->expects(self::once())->method('getTranslations')->with(
|
|
1101,
|
|
3,
|
|
CmsTranslationRepository::ENTITY_BLOG_POST,
|
|
self::isType('array')
|
|
)->willReturn(['name' => 'Deutscher Titel']);
|
|
|
|
$post = $this->createMock(Post::class);
|
|
$post->method('getId')->willReturn(1101);
|
|
$post->expects(self::once())->method('setData')->with('name', 'Deutscher Titel')->willReturnSelf();
|
|
|
|
$this->createApplier($repository)->apply($post);
|
|
}
|
|
|
|
public function testAppliesCollectionTranslationsWithOneRepositoryQuery(): void
|
|
{
|
|
$repository = $this->createMock(CmsTranslationRepository::class);
|
|
$repository->expects(self::once())->method('getTranslationsForEntities')->with(
|
|
[1101, 1102],
|
|
3,
|
|
CmsTranslationRepository::ENTITY_BLOG_POST,
|
|
self::isType('array')
|
|
)->willReturn([
|
|
1101 => ['name' => 'Erster Titel'],
|
|
1102 => ['name' => 'Zweiter Titel'],
|
|
]);
|
|
|
|
$first = $this->createMock(Post::class);
|
|
$first->method('getId')->willReturn(1101);
|
|
$first->expects(self::once())->method('setData')->with('name', 'Erster Titel')->willReturnSelf();
|
|
$second = $this->createMock(Post::class);
|
|
$second->method('getId')->willReturn(1102);
|
|
$second->expects(self::once())->method('setData')->with('name', 'Zweiter Titel')->willReturnSelf();
|
|
|
|
$this->createApplier($repository)->applyMany([$first, $second]);
|
|
}
|
|
|
|
private function createApplier(CmsTranslationRepository $repository): BlogPostTranslationApplier
|
|
{
|
|
$store = $this->createMock(StoreInterface::class);
|
|
$store->method('getId')->willReturn(3);
|
|
$storeManager = $this->createMock(StoreManagerInterface::class);
|
|
$storeManager->method('getStore')->willReturn($store);
|
|
$state = $this->createMock(State::class);
|
|
$state->method('getAreaCode')->willReturn('frontend');
|
|
|
|
return new BlogPostTranslationApplier($repository, $storeManager, $state);
|
|
}
|
|
}
|