|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Smartling\ContentTypes\Elementor; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Smartling\ContentTypes\ContentTypeHelper; |
| 7 | +use Smartling\ContentTypes\Elementor\Elements\Gallery; |
| 8 | +use Smartling\ContentTypes\ExternalContentElementor; |
| 9 | +use Smartling\Models\Content; |
| 10 | +use Smartling\Models\RelatedContentInfo; |
| 11 | +use Smartling\Submissions\SubmissionEntity; |
| 12 | + |
| 13 | +class GalleryTest extends TestCase |
| 14 | +{ |
| 15 | + private function makeWidget(array $settings = []): Gallery |
| 16 | + { |
| 17 | + return new Gallery([ |
| 18 | + 'id' => '14d5abc', |
| 19 | + 'elType' => 'widget', |
| 20 | + 'widgetType' => 'gallery', |
| 21 | + 'settings' => $settings, |
| 22 | + 'elements' => [], |
| 23 | + ]); |
| 24 | + } |
| 25 | + |
| 26 | + public function testRelated(): void |
| 27 | + { |
| 28 | + $imageSourceId = 21162; |
| 29 | + $imageTargetId = 31162; |
| 30 | + |
| 31 | + $externalContentElementor = $this->createMock(ExternalContentElementor::class); |
| 32 | + $externalContentElementor->method('getTargetId') |
| 33 | + ->with(0, $imageSourceId, 0, ContentTypeHelper::POST_TYPE_ATTACHMENT)->willReturn($imageTargetId); |
| 34 | + |
| 35 | + $this->assertEquals( |
| 36 | + $imageTargetId, |
| 37 | + $this->makeWidget(['gallery' => [ |
| 38 | + ['id' => 21161, 'url' => 'https://example.com/1.webp'], |
| 39 | + ['id' => $imageSourceId, 'url' => 'https://example.com/2.webp'], |
| 40 | + ['id' => 21163, 'url' => 'https://example.com/3.webp'], |
| 41 | + ]]) |
| 42 | + ->setRelations( |
| 43 | + new Content($imageSourceId, ContentTypeHelper::POST_TYPE_ATTACHMENT), |
| 44 | + $externalContentElementor, |
| 45 | + 'settings/gallery/1/id', |
| 46 | + $this->createMock(SubmissionEntity::class), |
| 47 | + )->toArray()['settings']['gallery'][1]['id'], |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + public function testGetTranslatableStrings(): void |
| 52 | + { |
| 53 | + $strings = $this->makeWidget(['galleries' => [ |
| 54 | + ['gallery_title' => 'New Gallery', '_id' => '04c68ec'], |
| 55 | + ['gallery_title' => 'Second Gallery', '_id' => 'ab12345'], |
| 56 | + ]])->getTranslatableStrings(); |
| 57 | + |
| 58 | + $this->assertEquals('New Gallery', $strings['14d5abc']['galleries/04c68ec']['gallery_title']); |
| 59 | + $this->assertEquals('Second Gallery', $strings['14d5abc']['galleries/ab12345']['gallery_title']); |
| 60 | + } |
| 61 | + |
| 62 | + public function testSetTargetContent(): void |
| 63 | + { |
| 64 | + $result = $this->makeWidget(['galleries' => [ |
| 65 | + ['gallery_title' => 'New Gallery', '_id' => '04c68ec'], |
| 66 | + ['gallery_title' => 'Second Gallery', '_id' => 'ab12345'], |
| 67 | + ]])->setTargetContent( |
| 68 | + $this->createMock(ExternalContentElementor::class), |
| 69 | + new RelatedContentInfo([]), |
| 70 | + [ |
| 71 | + '14d5abc' => [ |
| 72 | + 'galleries' => [ |
| 73 | + '04c68ec' => ['gallery_title' => 'Translated Gallery'], |
| 74 | + 'ab12345' => ['gallery_title' => 'Translated Second'], |
| 75 | + ], |
| 76 | + ], |
| 77 | + ], |
| 78 | + $this->createMock(SubmissionEntity::class), |
| 79 | + )->toArray(); |
| 80 | + |
| 81 | + $this->assertEquals('Translated Gallery', $result['settings']['galleries'][0]['gallery_title']); |
| 82 | + $this->assertEquals('Translated Second', $result['settings']['galleries'][1]['gallery_title']); |
| 83 | + } |
| 84 | +} |
0 commit comments