|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Catalog\Model\Product\Price; |
| 9 | + |
| 10 | +use Magento\Catalog\Api\Data\SpecialPriceInterface; |
| 11 | +use Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test special price storage model |
| 17 | + */ |
| 18 | +class SpecialPriceStorageTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var SpecialPriceStorage |
| 22 | + */ |
| 23 | + private $model; |
| 24 | + /** |
| 25 | + * @var SpecialPriceInterfaceFactory |
| 26 | + */ |
| 27 | + private $specialPriceFactory; |
| 28 | + |
| 29 | + /** |
| 30 | + * @inheritDoc |
| 31 | + */ |
| 32 | + protected function setUp(): void |
| 33 | + { |
| 34 | + parent::setUp(); |
| 35 | + $objectManager = Bootstrap::getObjectManager(); |
| 36 | + $this->model = $objectManager->get(SpecialPriceStorage::class); |
| 37 | + $this->specialPriceFactory = $objectManager->get(SpecialPriceInterfaceFactory::class); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test that price update validation works correctly |
| 42 | + * |
| 43 | + * @magentoDataFixture Magento/Catalog/_files/category_product.php |
| 44 | + */ |
| 45 | + public function testUpdateValidationResult() |
| 46 | + { |
| 47 | + $date = new \Datetime('+2 days'); |
| 48 | + $date->setTime(0, 0); |
| 49 | + /** @var SpecialPriceInterface $price */ |
| 50 | + $price = $this->specialPriceFactory->create(); |
| 51 | + $price->setSku('invalid') |
| 52 | + ->setStoreId(0) |
| 53 | + ->setPrice(5.0) |
| 54 | + ->setPriceFrom($date->format('Y-m-d H:i:s')) |
| 55 | + ->setPriceTo( |
| 56 | + $date->modify('+1 day') |
| 57 | + ->format('Y-m-d H:i:s') |
| 58 | + ); |
| 59 | + $result = $this->model->update([$price]); |
| 60 | + $this->assertCount(1, $result); |
| 61 | + $this->assertStringContainsString( |
| 62 | + 'The product that was requested doesn\'t exist.', |
| 63 | + (string) $result[0]->getMessage() |
| 64 | + ); |
| 65 | + $price->setSku('simple333'); |
| 66 | + $result = $this->model->update([$price]); |
| 67 | + $this->assertCount(0, $result); |
| 68 | + } |
| 69 | +} |
0 commit comments