-
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.
Merge remote-tracking branches 'local/ACP2E-1214', 'local/ACP2E-1223'…
… and 'local/ACP2E-1296' into PR_combine
- Loading branch information
Showing
8 changed files
with
251 additions
and
25 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
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
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
93 changes: 93 additions & 0 deletions
93
app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Filter/FormTest.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,93 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Reports\Test\Unit\Block\Adminhtml\Filter; | ||
|
||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Framework\Data\Form; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Data\Form\Element\Collection; | ||
use Magento\Framework\Data\FormFactory; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Registry; | ||
use Magento\Framework\UrlInterface; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
|
||
class FormTest extends TestCase | ||
{ | ||
/** | ||
* @var Context|MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var Registry|MockObject | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var FormFactory|MockObject | ||
*/ | ||
private $formFactory; | ||
|
||
/** | ||
* @var \Magento\Reports\Block\Adminhtml\Filter\Form | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->context = $this->createMock(Context::class); | ||
$this->registry = $this->createMock(Registry::class); | ||
$this->formFactory = $this->createMock(FormFactory::class); | ||
$this->context->method('getUrlBuilder') | ||
->willReturn($this->getMockForAbstractClass(UrlInterface::class)); | ||
$this->model = new \Magento\Reports\Block\Adminhtml\Filter\Form( | ||
$this->context, | ||
$this->registry, | ||
$this->formFactory | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws \ReflectionException | ||
*/ | ||
public function testMultiselectInitialValues(): void | ||
{ | ||
$this->context->method('getUrlBuilder') | ||
->willReturn($this->getMockForAbstractClass(UrlInterface::class)); | ||
$this->model->setData('filter_data', new DataObject(['multiselect' => ['5', '6']])); | ||
$form = $this->getMockBuilder(Form::class) | ||
->disableOriginalConstructor() | ||
->onlyMethods(['getElements']) | ||
->getMockForAbstractClass(); | ||
$element = $this->getMockBuilder(AbstractElement::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
|
||
$element->setId('multiselect'); | ||
$form->method('getElements')->willReturn(new Collection($form)); | ||
$reflection = new ReflectionClass($form); | ||
$reflectionProp = $reflection->getProperty('_allElements'); | ||
$reflectionProp->setAccessible(true); | ||
$reflectionProp->setValue($form, new Collection($form)); | ||
$form->addElement($element); | ||
$this->model->setForm($form); | ||
$reflection = new ReflectionClass($this->model); | ||
$reflectionMethod = $reflection->getMethod('_initFormValues'); | ||
$reflectionMethod->setAccessible(true); | ||
$reflectionMethod->invoke($this->model); | ||
$this->assertEquals(['5', '6'], $this->model->getForm()->getElement('multiselect')->getValue()); | ||
} | ||
} |
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
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
105 changes: 105 additions & 0 deletions
105
app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/MassDeleteTest.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,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product; | ||
|
||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Message\ManagerInterface; | ||
use Magento\Framework\Registry; | ||
use Magento\Review\Controller\Adminhtml\Product\MassDelete; | ||
use Magento\Review\Model\RatingFactory; | ||
use Magento\Review\Model\ResourceModel\Review as ReviewResourceModel; | ||
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection; | ||
use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory; | ||
use Magento\Review\Model\ReviewFactory; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MassDeleteTest extends TestCase | ||
{ | ||
/** | ||
* @var MassDelete | ||
*/ | ||
private $massDelete; | ||
|
||
/** | ||
* @var RequestInterface|MockObject | ||
*/ | ||
private $requestMock; | ||
|
||
/** | ||
* @var ReviewCollectionFactory|MockObject | ||
*/ | ||
private $collectionFactoryMock; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$contextMock = $this->createMock(Context::class); | ||
$this->requestMock = $this->createMock(RequestInterface::class); | ||
$contextMock->method('getRequest') | ||
->willReturn($this->requestMock); | ||
$messageManagerMock = $this->createMock(ManagerInterface::class); | ||
$contextMock->method('getMessageManager') | ||
->willReturn($messageManagerMock); | ||
$resultFactoryMock = $this->createMock(ResultFactory::class); | ||
$contextMock->method('getResultFactory') | ||
->willReturn($resultFactoryMock); | ||
$resultMock = $this->createMock(Redirect::class); | ||
$resultFactoryMock->method('create') | ||
->willReturn($resultMock); | ||
|
||
$coreRegistryMock = $this->createMock(Registry::class); | ||
$reviewFactoryMock = $this->createMock(ReviewFactory::class); | ||
$ratingFactoryMock = $this->createMock(RatingFactory::class); | ||
$this->collectionFactoryMock = $this->createMock(ReviewCollectionFactory::class); | ||
|
||
$this->massDelete = new MassDelete( | ||
$contextMock, | ||
$coreRegistryMock, | ||
$reviewFactoryMock, | ||
$ratingFactoryMock, | ||
$this->collectionFactoryMock | ||
); | ||
} | ||
|
||
public function testExecute(): void | ||
{ | ||
$this->requestMock->expects(self::atLeastOnce()) | ||
->method('getParam') | ||
->willReturnMap( | ||
[ | ||
['reviews', null, [10, 20]], | ||
['ret', 'index', 'index'], | ||
] | ||
); | ||
|
||
$collectionMock = $this->createMock(ReviewCollection::class); | ||
$this->collectionFactoryMock->expects(self::once()) | ||
->method('create') | ||
->willReturn($collectionMock); | ||
$resource = $this->createMock(ReviewResourceModel::class); | ||
$collectionMock->method('getResource') | ||
->willReturn($resource); | ||
$resource->method('getIdFieldName') | ||
->willReturn('id'); | ||
$collectionMock->expects(self::once()) | ||
->method('addFieldToFilter') | ||
->with('main_table.id', [10, 20]) | ||
->willReturnSelf(); | ||
$collectionMock->expects(self::once()) | ||
->method('addStoreData') | ||
->willReturnSelf(); | ||
|
||
$this->massDelete->execute(); | ||
} | ||
} |
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