Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductPriceWithDimensionTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\Catalog\Model;
9 
14 
24 class ProductPriceWithDimensionTest extends \PHPUnit\Framework\TestCase
25 {
29  protected $_model;
30 
34  private $productRepository;
35 
39  protected function setUp()
40  {
41  $this->_model = Bootstrap::getObjectManager()->create(Product::class);
42  $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
43  }
44 
48  public function testGetPrice()
49  {
50  $this->assertEmpty($this->_model->getPrice());
51  $this->_model->setPrice(10.0);
52  $this->assertEquals(10.0, $this->_model->getPrice());
53  }
54 
58  public function testGetPriceModel()
59  {
60  $default = $this->_model->getPriceModel();
61  $this->assertInstanceOf(\Magento\Catalog\Model\Product\Type\Price::class, $default);
62  $this->assertSame($default, $this->_model->getPriceModel());
63  }
64 
68  public function testGetTierPrice()
69  {
70  $this->assertEquals([], $this->_model->getTierPrice());
71  }
72 
76  public function testGetTierPriceCount()
77  {
78  $this->assertEquals(0, $this->_model->getTierPriceCount());
79  }
80 
84  public function testGetFormatedPrice()
85  {
86  $this->assertEquals('<span class="price">$0.00</span>', $this->_model->getFormatedPrice());
87  }
88 
92  public function testSetGetFinalPrice()
93  {
94  $this->assertEquals(0, $this->_model->getFinalPrice());
95  $this->_model->setPrice(10);
96  $this->_model->setFinalPrice(10);
97  $this->assertEquals(10, $this->_model->getFinalPrice());
98  }
99 
104  public function testGetMinPrice(): void
105  {
106  $product = $this->productRepository->get('simple');
107  $collection = Bootstrap::getObjectManager()->create(Collection::class);
108  $collection->addIdFilter($product->getId());
109  $collection->addPriceData();
110  $collection->load();
112  $product = $collection->getFirstItem();
113  $this->assertEquals(323, $product->getData('min_price'));
114  }
115 
119  public function testGetMinPriceForComposite()
120  {
121  $confProduct = $this->productRepository->get('configurable');
122  $collection = Bootstrap::getObjectManager()->create(Collection::class);
123  $collection->addIdFilter($confProduct->getId());
124  $collection->addPriceData();
125  $collection->load();
126  $product = $collection->getFirstItem();
127  $this->assertEquals(10, $product->getData('min_price'));
128 
129  $childProduct = $this->productRepository->get('simple_10');
130  $stockRegistry = Bootstrap::getObjectManager()->get(StockRegistryInterface::class);
131  $stockItem = $stockRegistry->getStockItem($childProduct->getId());
132  $stockItem->setIsInStock(false);
133  $stockRegistry->updateStockItemBySku($childProduct->getSku(), $stockItem);
134  $collection->clear()->load();
135  $product = $collection->getFirstItem();
136  $this->assertEquals(20, $product->getData('min_price'));
137  }
138 }