Exemplo n.º 1
0
 /**
  * testGetGroupPrices
  * testSetGroupPrices
  *
  * @dataProvider pricesDataProvider
  */
 public function testGroupPrices($priceScope, $expectedWebsiteId)
 {
     // establish the behavior of the mocks
     $this->scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue($priceScope));
     $this->websiteMock->expects($this->any())->method('getId')->will($this->returnValue($expectedWebsiteId));
     $this->gpFactory->expects($this->any())->method('create')->will($this->returnCallback(function () {
         return $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\GroupPrice');
     }));
     // create sample GroupPrice objects that would be coming from a REST call
     $gp1 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\GroupPrice');
     $gp1->setValue(10);
     $gp1->setCustomerGroupId(1);
     $gp2 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\GroupPrice');
     $gp2->setValue(20);
     $gp2->setCustomerGroupId(2);
     $gps = [$gp1, $gp2];
     // force the product to have null group prices
     $this->product->setData($this::KEY_GROUP_PRICE, null);
     $this->assertNull($this->product->getData($this::KEY_GROUP_PRICE));
     // set the product with the GroupPrice objects
     $this->model->setGroupPrices($this->product, $gps);
     // test the data actually set on the product
     $gpArray = $this->product->getData($this::KEY_GROUP_PRICE);
     $this->assertNotNull($gpArray);
     $this->assertTrue(is_array($gpArray));
     $this->assertEquals(sizeof($gps), sizeof($gpArray));
     for ($i = 0; $i < sizeof($gps); $i++) {
         $gpData = $gpArray[$i];
         $this->assertEquals($expectedWebsiteId, $gpData['website_id'], 'Website Id does not match');
         $this->assertEquals($gps[$i]->getValue(), $gpData['price'], 'Price/Value does not match');
         $this->assertEquals($gps[$i]->getValue(), $gpData['website_price'], 'WebsitePrice/Value does not match');
         $this->assertEquals($gps[$i]->getCustomerGroupId(), $gpData['cust_group'], 'Customer group Id does not match');
     }
     // test with the data retrieved as a REST object
     $gpRests = $this->model->getGroupPrices($this->product);
     $this->assertNotNull($gpRests);
     $this->assertTrue(is_array($gpRests));
     $this->assertEquals(sizeof($gps), sizeof($gpRests));
     for ($i = 0; $i < sizeof($gps); $i++) {
         $this->assertEquals($gps[$i]->getValue(), $gpRests[$i]->getValue(), 'REST: Price/Value does not match');
         $this->assertEquals($gps[$i]->getCustomerGroupId(), $gpRests[$i]->getCustomerGroupId(), 'REST: Customer group Id does not match');
     }
 }