|
| 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\Attribute\Backend; |
| 9 | + |
| 10 | +use Magento\Catalog\Api\Data\ProductInterfaceFactory; |
| 11 | +use Magento\Catalog\Model\Product; |
| 12 | +use Magento\Eav\Model\Config; |
| 13 | +use Magento\Framework\Exception\LocalizedException; |
| 14 | +use Magento\Framework\ObjectManagerInterface; |
| 15 | +use Magento\TestFramework\Helper\Bootstrap; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +/** |
| 19 | + * Test class for backend stock attribute model. |
| 20 | + * |
| 21 | + * @see \Magento\Catalog\Model\Product\Attribute\Backend\Stock |
| 22 | + * |
| 23 | + * @magentoAppArea adminhtml |
| 24 | + */ |
| 25 | +class StockTest extends TestCase |
| 26 | +{ |
| 27 | + /** @var ObjectManagerInterface */ |
| 28 | + private $objectManager; |
| 29 | + |
| 30 | + /** @var ProductInterfaceFactory */ |
| 31 | + private $productFactory; |
| 32 | + |
| 33 | + /** @var Stock */ |
| 34 | + private $model; |
| 35 | + |
| 36 | + /** |
| 37 | + * @inheritdoc |
| 38 | + */ |
| 39 | + protected function setUp(): void |
| 40 | + { |
| 41 | + parent::setUp(); |
| 42 | + |
| 43 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 44 | + $this->productFactory = $this->objectManager->get(ProductInterfaceFactory::class); |
| 45 | + $this->model = $this->objectManager->get(Stock::class); |
| 46 | + $this->model->setAttribute( |
| 47 | + $this->objectManager->get(Config::class)->getAttribute(Product::ENTITY, 'quantity_and_stock_status') |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return void |
| 53 | + */ |
| 54 | + public function testValidate(): void |
| 55 | + { |
| 56 | + $this->expectException(LocalizedException::class); |
| 57 | + $this->expectErrorMessage((string)__('Please enter a valid number in this field.')); |
| 58 | + $product = $this->productFactory->create(); |
| 59 | + $product->setQuantityAndStockStatus(['qty' => 'string']); |
| 60 | + $this->model->validate($product); |
| 61 | + } |
| 62 | +} |
0 commit comments