|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\AdobeStockClient\Test\Integration\Model\Client; |
| 10 | + |
| 11 | +use AdobeStock\Api\Client\AdobeStock; |
| 12 | +use AdobeStock\Api\Models\StockFile; |
| 13 | +use AdobeStock\Api\Response\Files as FilesResponse; |
| 14 | +use Magento\AdobeStockClient\Model\Client\Files; |
| 15 | +use Magento\AdobeStockClient\Model\ConnectionFactory; |
| 16 | +use Magento\Framework\Exception\IntegrationException; |
| 17 | +use Magento\TestFramework\Helper\Bootstrap; |
| 18 | +use PHPUnit\Framework\MockObject\MockObject; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * Test client files for communication to Adobe Stock API. |
| 23 | + */ |
| 24 | +class FilesTest extends TestCase |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @var Files |
| 28 | + */ |
| 29 | + private $files; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var AdobeStock|MockObject |
| 33 | + */ |
| 34 | + private $connection; |
| 35 | + |
| 36 | + /** |
| 37 | + * Prepare objects. |
| 38 | + */ |
| 39 | + protected function setUp(): void |
| 40 | + { |
| 41 | + $this->connection = $this->createMock(AdobeStock::class); |
| 42 | + $response = $this->createMock(FilesResponse::class); |
| 43 | + $response->expects($this->once()) |
| 44 | + ->method('getFiles') |
| 45 | + ->willReturn($this->getStockFiles()); |
| 46 | + $this->connection->expects($this->once()) |
| 47 | + ->method('getFiles') |
| 48 | + ->willReturn($response); |
| 49 | + /** @var ConnectionFactory|MockObject $connectionFactory */ |
| 50 | + $connectionFactory = $this->createMock(ConnectionFactory::class); |
| 51 | + $connectionFactory->expects($this->once()) |
| 52 | + ->method('create') |
| 53 | + ->willReturn($this->connection); |
| 54 | + $this->files = Bootstrap::getObjectManager()->create( |
| 55 | + Files::class, |
| 56 | + [ |
| 57 | + 'connectionFactory' => $connectionFactory |
| 58 | + ] |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Test execute method return data. |
| 64 | + * |
| 65 | + * @throws IntegrationException |
| 66 | + */ |
| 67 | + public function testExecute(): void |
| 68 | + { |
| 69 | + $files = $this->files->execute(['1', '2', '3'], []); |
| 70 | + |
| 71 | + $this->assertIsArray($files); |
| 72 | + $this->assertCount(3, $files); |
| 73 | + $this->assertEquals( |
| 74 | + 'https://test.url/2', |
| 75 | + $files[1]['comp_url'] |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Result files. |
| 81 | + * |
| 82 | + * @return StockFile[] |
| 83 | + */ |
| 84 | + private function getStockFiles(): array |
| 85 | + { |
| 86 | + $stockFilesData = [ |
| 87 | + [ |
| 88 | + 'id' => 1, |
| 89 | + 'comp_url' => 'https://test.url/1', |
| 90 | + 'thumbnail_240_url' => 'https://test.url/1', |
| 91 | + 'width' => 110, |
| 92 | + 'height' => 210, |
| 93 | + 'some_bool_param' => false, |
| 94 | + 'some_nullable_param' => null, |
| 95 | + 'category' => [ |
| 96 | + 'id' => 1, |
| 97 | + 'name' => 'Test' |
| 98 | + ] |
| 99 | + ], |
| 100 | + [ |
| 101 | + 'id' => 2, |
| 102 | + 'comp_url' => 'https://test.url/2', |
| 103 | + 'thumbnail_240_url' => 'https://test.url/2', |
| 104 | + 'width' => 120, |
| 105 | + 'height' => 220, |
| 106 | + 'some_bool_params' => false, |
| 107 | + 'some_nullable_param' => 1, |
| 108 | + 'category' => [ |
| 109 | + 'id' => 1, |
| 110 | + 'name' => 'Test' |
| 111 | + ] |
| 112 | + ], |
| 113 | + [ |
| 114 | + 'id' => 3, |
| 115 | + 'comp_url' => 'https://test.url/3', |
| 116 | + 'thumbnail_240_url' => 'https://test.url/3', |
| 117 | + 'width' => 130, |
| 118 | + 'height' => 230, |
| 119 | + 'some_bool_params' => true, |
| 120 | + 'some_nullable_param' => 2, |
| 121 | + 'category' => [ |
| 122 | + 'id' => 1, |
| 123 | + 'name' => 'Test' |
| 124 | + ] |
| 125 | + ], |
| 126 | + ]; |
| 127 | + |
| 128 | + $stockFiles = []; |
| 129 | + foreach ($stockFilesData as $stockFileData) { |
| 130 | + $stockFiles[] = new StockFile($stockFileData); |
| 131 | + } |
| 132 | + |
| 133 | + return $stockFiles; |
| 134 | + } |
| 135 | +} |
0 commit comments