Skip to content

Commit af7fa26

Browse files
committed
Adding integration tests for product review
1 parent 6b109f4 commit af7fa26

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Review\Controller;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Framework\Data\Form\FormKey;
11+
use Magento\Framework\Message\MessageInterface;
12+
use Magento\TestFramework\Request;
13+
use Magento\TestFramework\TestCase\AbstractController;
14+
15+
/**
16+
* Test review product controller behavior
17+
*
18+
* @magentoAppArea frontend
19+
*/
20+
class CaseCheckUnsuccessfulAddingProductReviewTest extends AbstractController
21+
{
22+
/**
23+
* Test adding a review for allowed guests with incomplete data by a not logged in user
24+
*
25+
* @magentoDbIsolation enabled
26+
* @magentoAppIsolation enabled
27+
* @magentoConfigFixture default_store catalog/review/allow_guest 1
28+
* @magentoDataFixture Magento/Catalog/_files/products.php
29+
*/
30+
public function testAttemptForGuestToAddReviewsWithIncompleteData()
31+
{
32+
$product = $this->getProduct();
33+
/** @var FormKey $formKey */
34+
$formKey = $this->_objectManager->get(FormKey::class);
35+
$post = [
36+
'nickname' => 'Test nick',
37+
'title' => 'Summary',
38+
'form_key' => $formKey->getFormKey(),
39+
];
40+
$this->prepareRequestData($post);
41+
$this->dispatch('review/product/post/id/' . $product->getId());
42+
$this->assertSessionMessages(
43+
$this->equalTo(['Please enter a review.']),
44+
MessageInterface::TYPE_ERROR
45+
);
46+
}
47+
48+
/**
49+
* Test adding a review for not allowed guests by a guest
50+
*
51+
* @magentoDbIsolation enabled
52+
* @magentoAppIsolation enabled
53+
* @magentoConfigFixture default_store catalog/review/allow_guest 0
54+
* @magentoDataFixture Magento/Catalog/_files/products.php
55+
*/
56+
public function testAttemptForGuestToAddReview()
57+
{
58+
$product = $this->getProduct();
59+
/** @var FormKey $formKey */
60+
$formKey = $this->_objectManager->get(FormKey::class);
61+
$post = [
62+
'nickname' => 'Test nick',
63+
'title' => 'Summary',
64+
'detail' => 'Test Details',
65+
'form_key' => $formKey->getFormKey(),
66+
];
67+
68+
$this->prepareRequestData($post);
69+
$this->dispatch('review/product/post/id/' . $product->getId());
70+
71+
$this->assertRedirect($this->stringContains('customer/account/login'));
72+
}
73+
74+
/**
75+
* @return ProductInterface
76+
*/
77+
private function getProduct()
78+
{
79+
return $this->_objectManager->get(ProductRepositoryInterface::class)->get('custom-design-simple-product');
80+
}
81+
82+
/**
83+
* @param array $postData
84+
* @return void
85+
*/
86+
private function prepareRequestData($postData)
87+
{
88+
$this->getRequest()->setMethod(Request::METHOD_POST);
89+
$this->getRequest()->setPostValue($postData);
90+
}
91+
}

0 commit comments

Comments
 (0)