createMock(Post::class); $post->method('load')->with(1101)->willReturnSelf(); $post->method('getId')->willReturn(1101); $post->method('getData')->willReturnMap([ ['name', null, 'English title'], ['short_description', null, 'English summary'], ['post_content', null, '
English content
'], ['meta_title', null, 'English meta title'], ['meta_keywords', null, 'English keywords'], ['meta_description', null, 'English meta description'], ]); $postFactory = $this->createMock(PostFactory::class); $postFactory->method('create')->willReturn($post); $repository = $this->createMock(CmsTranslationRepository::class); $repository->expects(self::exactly(2))->method('getTranslations')->willReturnOnConsecutiveCalls( ['name' => 'Titre français'], [] ); $skippedFields = $this->createMock(SkippedFields::class); $fields = (new BlogPostEntity($postFactory, $repository, $skippedFields))->getFields(1101, 2, 3); self::assertSame('Titre français', $fields[0]['source_value']); self::assertSame('English title', $fields[0]['target_value']); self::assertTrue($fields[0]['use_default']); self::assertSame('post_content', $fields[2]['code']); self::assertTrue($fields[2]['is_html']); } public function testSavesTranslationAndDeletesUseDefaultFields(): void { $post = $this->createMock(Post::class); $post->method('load')->with(1101)->willReturnSelf(); $post->method('getId')->willReturn(1101); $postFactory = $this->createMock(PostFactory::class); $postFactory->method('create')->willReturn($post); $repository = $this->createMock(CmsTranslationRepository::class); $repository->expects(self::once())->method('deleteTranslations')->with( 1101, 3, CmsTranslationRepository::ENTITY_BLOG_POST, ['meta_keywords'] ); $repository->expects(self::once())->method('saveTranslations')->with( 1101, 3, CmsTranslationRepository::ENTITY_BLOG_POST, ['name' => 'Deutscher Titel'] ); $entity = new BlogPostEntity( $postFactory, $repository, $this->createMock(SkippedFields::class) ); $entity->apply( 1101, 3, ['name' => 'Deutscher Titel', 'url_key' => 'must-not-be-saved'], ['meta_keywords' => true] ); } }