-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
product review DataProvider sorting, integration test
- Loading branch information
1 parent
c1eb748
commit 1c6672e
Showing
2 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...s/integration/testsuite/Magento/Review/Ui/DataProvider/Product/ReviewDataProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Review\Ui\DataProvider\Product; | ||
|
||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for \Magento\Review\Ui\DataProvider\Product\ReviewDataProvider. | ||
*/ | ||
class ReviewDataProviderTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $modelParams = [ | ||
'name' => 'review_listing_data_source', | ||
'primaryFieldName' => 'review_id', | ||
'requestFieldName' => 'entity_id', | ||
]; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* Sorting dataProvider test | ||
* | ||
* @magentoDataFixture Magento/Review/_files/different_reviews.php | ||
* @dataProvider sortingDataProvider | ||
* | ||
* @param array $sorting | ||
* @param array $expectedSortedTitles | ||
* @return void | ||
*/ | ||
public function testSorting(array $sorting, array $expectedSortedTitles): void | ||
{ | ||
$request = $this->objectManager->create(RequestInterface::class); | ||
$request->setParam('sorting', $sorting); | ||
$request->setParam('current_product_id', 1); | ||
|
||
$dataProvider = $this->objectManager->create( | ||
ReviewDataProvider::class, | ||
array_merge($this->modelParams, ['request' => $request]) | ||
); | ||
|
||
$result = $dataProvider->getData(); | ||
|
||
$this->assertEquals($this->getItemsField($result, 'title'), $expectedSortedTitles); | ||
} | ||
|
||
/** | ||
* Return items field data | ||
* | ||
* @param array $arrItems | ||
* @param string $field | ||
* @return array | ||
*/ | ||
private function getItemsField(array $arrItems, string $field): array | ||
{ | ||
$data = []; | ||
foreach ($arrItems['items'] as $review) { | ||
$data[] = $review[$field]; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* DataProvider for testSorting | ||
* | ||
* @return array | ||
*/ | ||
public function sortingDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
['field' => 'title', 'direction' => 'asc'], | ||
['1 filter second review', '2 filter first review', 'Review Summary'], | ||
], | ||
[ | ||
['field' => 'title', 'direction' => 'desc'], | ||
['Review Summary', '2 filter first review', '1 filter second review'], | ||
], | ||
]; | ||
} | ||
} |