Merge pull request #7698 from tuka217/promotion-priority-bug

[Promotion] Promotion with priority equals to null should be last
This commit is contained in:
Paweł Jędrzejewski 2017-03-14 15:54:16 +01:00 committed by GitHub
commit b562a924f9
6 changed files with 58 additions and 2 deletions

View file

@ -6,7 +6,8 @@ Feature: Editing promotion
Background:
Given the store operates on a single channel in "United States"
And there is a promotion "Christmas sale"
And there is a promotion "Christmas sale" with priority 0
And there is a promotion "Holiday sale" with priority 1
And I am logged in as an administrator
@ui
@ -59,3 +60,11 @@ Feature: Editing promotion
Given this promotion gives "$10.00" discount to every order
When the store also operates on another channel named "EU-WEB"
Then I should be able to modify a "Christmas sale" promotion
@ui
Scenario: Remove priority from existing promotion
Given I want to modify a "Christmas sale" promotion
When I remove its priority
And I save my changes
Then I should be notified that it has been successfully edited
And the "Christmas sale" promotion should have priority 1

View file

@ -117,6 +117,14 @@ final class ManagingPromotionsContext implements Context
$this->createPage->nameIt($name);
}
/**
* @When I remove its priority
*/
public function iRemoveItsPriority()
{
$this->updatePage->setPriority(null);
}
/**
* @Then the :promotionName promotion should appear in the registry
* @Then the :promotionName promotion should exist in the registry
@ -603,6 +611,16 @@ final class ManagingPromotionsContext implements Context
);
}
/**
* @Given the :promotion promotion should have priority :priority
*/
public function thePromotionsShouldHavePriority(PromotionInterface $promotion, $priority)
{
$this->iWantToModifyAPromotion($promotion);
Assert::same($this->updatePage->getPriority(), $priority);
}
/**
* @param string $element
* @param string $expectedMessage

View file

@ -24,6 +24,22 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
use NamesIt;
use ChecksCodeImmutability;
/**
* {@inheritdoc}
*/
public function setPriority($priority)
{
$this->getDocument()->fillField('Priority', $priority);
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->getElement('priority')->getValue();
}
/**
* {@inheritdoc}
*/
@ -116,6 +132,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
return [
'code' => '#sylius_promotion_code',
'priority' => '#sylius_promotion_priority',
'coupon_based' => '#sylius_promotion_couponBased',
'ends_at' => '#sylius_promotion_endsAt',
'ends_at_date' => '#sylius_promotion_endsAt_date',

View file

@ -19,6 +19,17 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface;
*/
interface UpdatePageInterface extends BaseUpdatePageInterface
{
/**
* @param int|null $priority
*/
public function setPriority($priority);
/**
* @return int
*/
public function getPriority();
/**
* @param string $name
*/

View file

@ -11,6 +11,7 @@
namespace Sylius\Bundle\PromotionBundle\Form\Type;
use Sylius\Bundle\PromotionBundle\Form\EventListener\SetPriorityFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

View file

@ -174,7 +174,7 @@ class Promotion implements PromotionInterface
*/
public function setPriority($priority)
{
$this->priority = $priority;
$this->priority = null === $priority ? -1 : $priority;
}
/**