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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Viewing product reviews on product's details page
And this product has also a review titled "Classic" and rated 5 added by customer "[email protected]"
And I am a logged in customer

@ui
@ui @api
Scenario: Viewing last 3 product reviews on product's details page
When I check this product's details
Then I should see 3 product reviews
Expand Down
44 changes: 44 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ public function iLeaveACommentTitled(string $comment, string $title, ?string $em
$this->client->addRequestData('email', $email);
}

/**
* @Then I should see :amount product reviews
*/
public function iShouldSeeProductReviews(int $amount = 0): void
{
/** @var ProductInterface $product */
$product = $this->sharedStorage->get('product');

$this->client->index();
$this->client->addFilter('reviewSubject', $this->iriConverter->getIriFromItem($product));
$this->client->addFilter('itemsPerPage', 3);
$this->client->addFilter('order[createdAt]', 'desc');
$this->client->filter();

Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $amount);
}

/**
* @Then I should see reviews titled :titleOne, :titleTwo and :titleThree
*/
public function iShouldSeeReviewsTitledAnd(string ...$titles): void
{
Assert::true($this->hasReviewsWithTitles($titles));
}

/**
* @Then I should not see review titled :title
*/
public function iShouldNotSeeReviewTitled(string $title): void
{
Assert::false($this->hasReviewsWithTitles([$title]));
}

/**
* @When I rate it with :rating point(s)
*/
Expand Down Expand Up @@ -126,4 +159,15 @@ public function iShouldNotSeeReviewTitledInTheList(string $title): void
{
Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($this->client->getLastResponse(), 'title', $title));
}

private function hasReviewsWithTitles(array $titles): bool
{
foreach ($titles as $title) {
if (!$this->responseChecker->hasItemWithValue($this->client->getLastResponse(), 'title', $title)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<attribute name="path">/shop/product-reviews</attribute>
<attribute name="filters">
<attribute>sylius.api.product_review_product_filter</attribute>
<attribute>sylius.api.product_review_date_filter</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
<tag name="api_platform.filter" />
</service>

<service id="sylius.api.product_review_date_filter" parent="api_platform.doctrine.orm.order_filter">
<argument type="collection">
<argument key="createdAt" />
</argument>
<tag name="api_platform.filter" />
</service>

<service id="sylius.api.product_order_filter" parent="api_platform.doctrine.orm.order_filter">
<argument type="collection">
<argument key="code" />
Expand Down