Skip to content

Commit

Permalink
Add & update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienPapet committed Nov 3, 2022
1 parent 3e62120 commit efabb27
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use PrestaShop\PrestaShop\Core\Domain\Product\Customization\QueryResult\CustomizationField;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\GetProductForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\QueryResult\ProductForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\ValueObject\OutOfStockType;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShop\PrestaShop\Core\Util\DateTime\DateTime as DateTimeUtil;
use RuntimeException;
Expand Down Expand Up @@ -312,6 +313,23 @@ protected function extractValueFromProductForEditing(ProductForEditing $productF
return $propertyAccessor->getValue($productForEditing, $pathsByNames[$propertyName]);
}

/**
* @param string $outOfStock
*
* @return int
*/
protected function convertOutOfStockToInt(string $outOfStock): int
{
$intValues = [
'default' => OutOfStockType::OUT_OF_STOCK_DEFAULT,
'available' => OutOfStockType::OUT_OF_STOCK_AVAILABLE,
'not_available' => OutOfStockType::OUT_OF_STOCK_NOT_AVAILABLE,
'invalid' => 42, // This random number is hardcoded intentionally to reflect invalid stock type
];

return $intValues[$outOfStock];
}

/**
* @return int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\CombinationStock;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\Exception\ProductStockConstraintException;
use PrestaShop\PrestaShop\Core\Util\DateTime\DateTime as DateTimeUtil;
use StockAvailable;
use StockAvailableCore;
use Tests\Integration\Behaviour\Features\Context\Util\PrimitiveUtils;

class UpdateCombinationStockFeatureContext extends AbstractCombinationFeatureContext
Expand Down Expand Up @@ -173,4 +175,32 @@ private function fillCommand(UpdateCombinationStockCommand $command, array $data
$command->setAvailableDate(new DateTime($dataRows['available date']));
}
}

/**
* @Then /^all combinations of product "([^"]*)" should have the stock policy to "([^"]*)"$/
*/
public function allCombinationsOfProductShouldHaveTheStockPolicyTo(string $reference, string $outOfStock)
{
$product = $this->getProductForEditing($reference);

$outOfStockInt = $this->convertOutOfStockToInt($outOfStock);
Assert::assertSame(
$product->getStockInformation()->getOutOfStockType(),
$outOfStockInt
);

$combinations = $this->getCombinationsList($reference);

foreach ($combinations->getCombinations() as $combination) {
$id = StockAvailable::getStockAvailableIdByProductId(
$this->getSharedStorage()->get($reference),
$combination->getCombinationId()
);

Assert::assertSame(
(int) (new StockAvailable($id))->out_of_stock,
$outOfStockInt
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\Query\GetEmployeesStockMovements;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\QueryResult\EmployeeStockMovement;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\QueryResult\StockMovement;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\ValueObject\OutOfStockType;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\ValueObject\StockId;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShopBundle\Api\QueryStockMovementParamsCollection;
Expand Down Expand Up @@ -448,23 +447,6 @@ private function setUpdateStockCommandData(array $data, UpdateProductStockInform
return $data;
}

/**
* @param string $outOfStock
*
* @return int
*/
private function convertOutOfStockToInt(string $outOfStock): int
{
$intValues = [
'default' => OutOfStockType::OUT_OF_STOCK_DEFAULT,
'available' => OutOfStockType::OUT_OF_STOCK_AVAILABLE,
'not_available' => OutOfStockType::OUT_OF_STOCK_NOT_AVAILABLE,
'invalid' => 42, // This random number is hardcoded intentionally to reflect invalid stock type
];

return $intValues[$outOfStock];
}

/**
* @param string $outOfStock
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,16 @@ Feature: Update product combination stock information in Back Office (BO)
| location | |
| available date | |
And product "product1" should have no stock movements

Scenario: I update product out of stock
And product "product1" should have following stock information:
| out_of_stock_type | default |
When I update product "product1" stock with following information:
| out_of_stock_type | available |
Then all combinations of product "product1" should have the stock policy to "available"
When I update product "product1" stock with following information:
| out_of_stock_type | default |
Then all combinations of product "product1" should have the stock policy to "default"
When I update product "product1" stock with following information:
| out_of_stock_type | not_available |
Then all combinations of product "product1" should have the stock policy to "not_available"

0 comments on commit efabb27

Please sign in to comment.