-
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.
Resolve Export Coupon Code Grid redirect to DashBoard when create New…
… Cart Price Rule issue24468
- Loading branch information
Showing
4 changed files
with
206 additions
and
28 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
87 changes: 87 additions & 0 deletions
87
...ode/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/ExportCouponsCsvTest.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,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Test\Unit\Controller\Adminhtml\Promo\Quote; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
use Magento\SalesRule\Controller\Adminhtml\Promo\Quote\ExportCouponsCsv; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\Response\Http\FileFactory; | ||
use Magento\Framework\View\Result\Layout; | ||
use Magento\Framework\View\LayoutInterface; | ||
use Magento\Framework\View\Element\AbstractBlock; | ||
use Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Grid; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExportCouponsCsvTest extends TestCase | ||
{ | ||
/** | ||
* @var ExportCouponsCsv | ||
*/ | ||
private $controller; | ||
|
||
/** | ||
* @var FileFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $fileFactoryMock; | ||
|
||
/** | ||
* @var ObjectManagerHelper | ||
*/ | ||
private $objectManagerHelper; | ||
|
||
/** | ||
* @var ResultFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $resultFactoryMock; | ||
|
||
/** | ||
* Setup environment | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManagerHelper = new ObjectManagerHelper($this); | ||
$this->fileFactoryMock = $this->createMock(FileFactory::class); | ||
$this->resultFactoryMock = $this->createMock(ResultFactory::class); | ||
|
||
$this->controller = $this->objectManagerHelper->getObject( | ||
ExportCouponsCsv::class, | ||
[ | ||
'fileFactory' => $this->fileFactoryMock, | ||
'resultFactory' => $this->resultFactoryMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test execute function | ||
*/ | ||
public function testExecute() | ||
{ | ||
$fileName = 'coupon_codes.csv'; | ||
|
||
$resultLayoutMock = $this->createMock(Layout::class); | ||
$layoutMock = $this->createMock(LayoutInterface::class); | ||
$contentMock = $this->createPartialMock(AbstractBlock::class, ['getCsvFile']); | ||
$this->resultFactoryMock | ||
->expects($this->once()) | ||
->method('create') | ||
->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayoutMock); | ||
$resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock); | ||
$layoutMock->expects($this->once())->method('createBlock')->with(Grid::class) | ||
->willReturn($contentMock); | ||
$contentMock->expects($this->once())->method('getCsvFile')->willReturn('csvFile'); | ||
$this->fileFactoryMock | ||
->expects($this->once()) | ||
->method('create') | ||
->with($fileName, 'csvFile', DirectoryList::VAR_DIR); | ||
|
||
$this->controller->execute(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...ode/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/ExportCouponsXmlTest.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,89 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Test\Unit\Controller\Adminhtml\Promo\Quote; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
use Magento\SalesRule\Controller\Adminhtml\Promo\Quote\ExportCouponsXml; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\Response\Http\FileFactory; | ||
use Magento\Framework\View\Result\Layout; | ||
use Magento\Framework\View\LayoutInterface; | ||
use Magento\Framework\View\Element\AbstractBlock; | ||
use Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Grid; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExportCouponsXmlTest extends TestCase | ||
{ | ||
/** | ||
* @var ExportCouponsXml | ||
*/ | ||
private $controller; | ||
|
||
/** | ||
* @var FileFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $fileFactoryMock; | ||
|
||
/** | ||
* @var ObjectManagerHelper | ||
*/ | ||
private $objectManagerHelper; | ||
|
||
/** | ||
* @var ResultFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $resultFactoryMock; | ||
|
||
/** | ||
* Setup environment | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManagerHelper = new ObjectManagerHelper($this); | ||
$this->fileFactoryMock = $this->createMock(FileFactory::class); | ||
$this->resultFactoryMock = $this->createMock(ResultFactory::class); | ||
|
||
$this->controller = $this->objectManagerHelper->getObject( | ||
ExportCouponsXml::class, | ||
[ | ||
'fileFactory' => $this->fileFactoryMock, | ||
'resultFactory' => $this->resultFactoryMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test execute function | ||
*/ | ||
public function testExecute() | ||
{ | ||
$fileName = 'coupon_codes.xml'; | ||
|
||
$resultLayoutMock = $this->createMock(Layout::class); | ||
$layoutMock = $this->createMock(LayoutInterface::class); | ||
$contentMock = $this->createPartialMock(AbstractBlock::class, ['getExcelFile']); | ||
$this->resultFactoryMock | ||
->expects($this->once()) | ||
->method('create') | ||
->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayoutMock); | ||
$resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock); | ||
$layoutMock->expects($this->once())->method('createBlock')->with(Grid::class) | ||
->willReturn($contentMock); | ||
$contentMock->expects($this->once())->method('getExcelFile') | ||
->with($fileName) | ||
->willReturn('xmlFile'); | ||
$this->fileFactoryMock | ||
->expects($this->once()) | ||
->method('create') | ||
->with($fileName, 'xmlFile', DirectoryList::VAR_DIR); | ||
|
||
$this->controller->execute(); | ||
} | ||
} |