Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90d8281

Browse files
authored
feature #13008 [Catalog Promotions] Add behat scenarios for endpoints (arti0090)
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | yes (behat for feature) | BC breaks? | no | Deprecations? | no | License | MIT Promised behats for #12994 Commits ------- 3e37138 Add delete behat with factory c690e3b Delete covered in behat be54912 Edit covered in behats 4e67186 Revert behat of delete 2912c4f Changing services and tests
2 parents 7d1712a + 2912c4f commit 90d8281

8 files changed

Lines changed: 67 additions & 14 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@managing_catalog_promotions
2+
Feature: Editing catalog promotion
3+
In order to change catalog promotion details
4+
As an Administrator
5+
I want to be able to edit a catalog promotion
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And there is a catalog promotion with "christmas_sale" code and "Christmas sale" name
10+
And I am logged in as an administrator
11+
12+
@api
13+
Scenario: Renaming a catalog promotion
14+
When I rename the "Christmas sale" catalog promotion to "Black Friday"
15+
Then I should be notified that it has been successfully edited
16+
And this catalog promotion name should be "Black Friday"

src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ public function iAddIt(): void
108108
$this->client->create();
109109
}
110110

111+
/**
112+
* @When /^I rename the ("[^"]+" catalog promotion) to "([^"]+)"$/
113+
*/
114+
public function iRenameTheCatalogPromotionTo(CatalogPromotionInterface $catalogPromotion, string $name): void
115+
{
116+
$this->client->buildUpdateRequest($catalogPromotion->getCode());
117+
$this->client->updateRequestData(['name' => $name]);
118+
$this->client->update();
119+
}
120+
111121
/**
112122
* @Then there should be :amount new catalog promotion on the list
113123
*/
@@ -138,10 +148,8 @@ public function thisCatalogPromotionShouldBeUsable(): void
138148
/**
139149
* @Then the catalog promotion :catalogPromotion should be available in channel :channel
140150
*/
141-
public function itShouldBeAvailableInChannel(
142-
CatalogPromotionInterface $catalogPromotion,
143-
ChannelInterface $channel
144-
): void {
151+
public function itShouldBeAvailableInChannel(CatalogPromotionInterface $catalogPromotion, ChannelInterface $channel): void
152+
{
145153
Assert::true(
146154
$this->responseChecker->hasValueInCollection(
147155
$this->client->show($catalogPromotion->getCode()),
@@ -151,4 +159,28 @@ public function itShouldBeAvailableInChannel(
151159
sprintf('Catalog promotion is not assigned to %s channel', $channel->getName())
152160
);
153161
}
162+
163+
/**
164+
* @Then I should be notified that it has been successfully edited
165+
*/
166+
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
167+
{
168+
Assert::true(
169+
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
170+
'Catalog promotion could not be edited'
171+
);
172+
}
173+
174+
/**
175+
* @Then /^(this catalog promotion) name should be "([^"]+)"$/
176+
*/
177+
public function thisCatalogPromotionNameShouldBe(CatalogPromotionInterface $catalogPromotion, string $name): void
178+
{
179+
$response = $this->client->show($catalogPromotion->getCode());
180+
181+
Assert::true(
182+
$this->responseChecker->hasValue($response, 'name', $name),
183+
sprintf('Catalog promotion\'s name %s does not exist', $name)
184+
);
185+
}
154186
}

src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Sylius\Behat\Context\Setup;
1515

1616
use Behat\Behat\Context\Context;
17-
use Behat\Behat\Tester\Exception\PendingException;
1817
use Doctrine\ORM\EntityManagerInterface;
1918
use Sylius\Behat\Service\SharedStorageInterface;
2019
use Sylius\Component\Core\Model\TaxonInterface;

src/Sylius/Behat/Context/Transform/CatalogPromotionContext.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ public function __construct(RepositoryInterface $catalogPromotionRepository)
2828
}
2929

3030
/**
31+
* @Transform /^"([^"]+)" catalog promotion$/
3132
* @Transform :catalogPromotion
3233
*/
3334
public function getCatalogPromotionByName(string $name): CatalogPromotionInterface
3435
{
3536
$catalogPromotion = $this->catalogPromotionRepository->findOneBy(['name' => $name]);
36-
Assert::notNull($catalogPromotion);
37+
38+
Assert::notNull(
39+
$catalogPromotion,
40+
sprintf('Catalog promotion with name "%s" does not exist', $name)
41+
);
3742

3843
return $catalogPromotion;
3944
}

src/Sylius/Behat/Resources/config/services/contexts/setup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293
<argument>%kernel.project_dir%</argument>
294294
</service>
295295

296-
<service id="sylius.behat.context.setup.catalog_promotion" class="Sylius\Behat\Context\Setup\CatalogPromotionContext">
296+
<service id="Sylius\Behat\Context\Setup\CatalogPromotionContext">
297297
<argument type="service" id="sylius.factory.catalog_promotion" />
298298
<argument type="service" id="sylius.manager.catalog_promotion" />
299299
<argument type="service" id="sylius.behat.shared_storage" />

src/Sylius/Behat/Resources/config/services/contexts/transform.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<argument type="service" id="sylius.fixture.example_factory.address" />
2323
</service>
2424

25+
<service id="Sylius\Behat\Context\Transform\CatalogPromotionContext">
26+
<argument type="service" id="sylius.repository.catalog_promotion" />
27+
</service>
28+
2529
<service id="sylius.behat.context.transform.channel" class="Sylius\Behat\Context\Transform\ChannelContext">
2630
<argument type="service" id="sylius.repository.channel" />
2731
</service>
@@ -164,9 +168,5 @@
164168
<argument type="service" id="sylius.repository.zone" />
165169
<argument type="service" id="sylius.repository.zone_member" />
166170
</service>
167-
168-
<service id="Sylius\Behat\Context\Transform\CatalogPromotionContext">
169-
<argument type="service" id="sylius.repository.catalog_promotion" />
170-
</service>
171171
</services>
172172
</container>

src/Sylius/Behat/Resources/config/suites/api/promotion/applying_catalog_promotions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ default:
77
contexts:
88
- sylius.behat.context.hook.doctrine_orm
99

10-
- sylius.behat.context.setup.catalog_promotion
1110
- sylius.behat.context.setup.channel
1211
- sylius.behat.context.setup.product
1312
- sylius.behat.context.setup.product_taxon
1413
- sylius.behat.context.setup.taxonomy
14+
- Sylius\Behat\Context\Setup\CatalogPromotionContext
1515

1616
- sylius.behat.context.transform.lexical
1717
- sylius.behat.context.transform.product

src/Sylius/Behat/Resources/config/suites/api/promotion/managing_catalog_promotions.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ default:
1010
- sylius.behat.context.transform.channel
1111
- sylius.behat.context.transform.shared_storage
1212
- Sylius\Behat\Context\Transform\CatalogPromotionContext
13-
14-
- sylius.behat.context.setup.channel
13+
1514
- sylius.behat.context.setup.admin_api_security
15+
- sylius.behat.context.setup.channel
16+
- Sylius\Behat\Context\Setup\CatalogPromotionContext
1617

1718
- sylius.behat.context.api.admin.managing_catalog_promotions
1819

0 commit comments

Comments
 (0)