Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/phpunit8' into phpunit8/module-C…
Browse files Browse the repository at this point in the history
…atalog

# Conflicts:
#	app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php
#	app/code/Magento/MediaGallery/Test/Unit/Model/ResourceModel/Keyword/SaveAssetLinksTest.php
  • Loading branch information
lbajsarowicz committed Apr 23, 2020
2 parents c21be03 + 0537aa9 commit c07b96d
Show file tree
Hide file tree
Showing 51 changed files with 1,025 additions and 662 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* Test for SaveAssetKeywords
*/
class SaveAssetKeywordsTest extends TestCase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
declare(strict_types=1);

namespace Magento\MediaGallery\Test\Unit\Model\Keyword\Command;
namespace Magento\MediaGallery\Test\Unit\Model\ResourceModel\Keyword;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
Expand All @@ -15,9 +15,6 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* Test for SaveAssetLinks
*/
class SaveAssetLinksTest extends TestCase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Magento\Framework\Escaper;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Newsletter\Block\Adminhtml\Queue\Preview;
use Magento\Newsletter\Block\Adminhtml\Queue\Preview as QueuePreview;
use Magento\Newsletter\Model\Queue;
use Magento\Newsletter\Model\QueueFactory;
use Magento\Newsletter\Model\Subscriber;
Expand All @@ -32,85 +32,100 @@
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PreviewTest extends TestCase
class PreviewTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
protected $objectManager;
private $objectManager;

/**
* @var Template|MockObject
*/
protected $template;
private $templateMock;

/**
* @var RequestInterface|MockObject
*/
protected $request;
private $requestMock;

/**
* @var Subscriber|MockObject
*/
protected $subscriber;
private $subscriberMock;

/**
* @var Queue|MockObject
*/
protected $queue;
private $queueMock;

/**
* @var StoreManagerInterface|MockObject
*/
protected $storeManager;
private $storeManagerMock;

/**
* @var Preview
* @var QueuePreview
*/
protected $preview;
private $preview;

protected function setUp(): void
{
$context = $this->createMock(Context::class);
$eventManager = $this->createMock(ManagerInterface::class);
$context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager));
$context->expects($this->once())->method('getEventManager')
->will($this->returnValue($eventManager));
$scopeConfig = $this->createMock(ScopeConfigInterface::class);
$context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
$this->request = $this->createMock(Http::class);
$context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
$this->storeManager = $this->createPartialMock(
$context->expects($this->once())->method('getScopeConfig')
->will($this->returnValue($scopeConfig));
$this->requestMock = $this->createMock(Http::class);
$context->expects($this->once())->method('getRequest')
->will($this->returnValue($this->requestMock));
$this->storeManagerMock = $this->createPartialMock(
StoreManager::class,
['getStores', 'getDefaultStoreView']
);
$context->expects($this->once())->method('getStoreManager')->will($this->returnValue($this->storeManager));
$context->expects($this->once())->method('getStoreManager')
->will($this->returnValue($this->storeManagerMock));
$appState = $this->createMock(State::class);
$context->expects($this->once())->method('getAppState')->will($this->returnValue($appState));
$context->expects($this->once())->method('getAppState')
->will($this->returnValue($appState));

$backendSession = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->getMock();

$context->expects($this->once())->method('getBackendSession')->willReturn($backendSession);
$context->expects($this->once())
->method('getBackendSession')
->willReturn($backendSession);

$templateFactory = $this->createPartialMock(TemplateFactory::class, ['create']);
$this->template = $this->createMock(Template::class);
$templateFactory->expects($this->once())->method('create')->will($this->returnValue($this->template));
$this->templateMock = $this->createMock(Template::class);
$templateFactory->expects($this->once())
->method('create')
->will($this->returnValue($this->templateMock));

$subscriberFactory = $this->createPartialMock(SubscriberFactory::class, ['create']);
$this->subscriber = $this->createMock(Subscriber::class);
$subscriberFactory->expects($this->once())->method('create')->will($this->returnValue($this->subscriber));
$this->subscriberMock = $this->createMock(Subscriber::class);
$subscriberFactory->expects($this->once())
->method('create')
->will($this->returnValue($this->subscriberMock));

$queueFactory = $this->createPartialMock(QueueFactory::class, ['create']);
$this->queue = $this->createPartialMock(Queue::class, ['load']);
$queueFactory->expects($this->any())->method('create')->will($this->returnValue($this->queue));
$this->queueMock = $this->createPartialMock(Queue::class, ['load']);
$queueFactory->expects($this->any())
->method('create')
->will($this->returnValue($this->queueMock));

$this->objectManager = new ObjectManager($this);

$escaper = $this->objectManager->getObject(Escaper::class);
$context->expects($this->once())->method('getEscaper')->willReturn($escaper);
$context->expects($this->once())
->method('getEscaper')
->willReturn($escaper);

$this->preview = $this->objectManager->getObject(
Preview::class,
QueuePreview::class,
[
'context' => $context,
'templateFactory' => $templateFactory,
Expand All @@ -124,27 +139,37 @@ public function testToHtmlEmpty()
{
/** @var Store $store */
$store = $this->createPartialMock(Store::class, ['getId']);
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->will($this->returnValue($store));
$this->storeManagerMock->expects($this->once())
->method('getDefaultStoreView')
->will($this->returnValue($store));
$result = $this->preview->toHtml();
$this->assertEquals('', $result);
}

public function testToHtmlWithId()
{
$this->request->expects($this->any())->method('getParam')->will(
$this->requestMock->expects($this->any())->method('getParam')->will(
$this->returnValueMap(
[
['id', null, 1],
['store_id', null, 0]
]
)
);
$this->queue->expects($this->once())->method('load')->will($this->returnSelf());
$this->template->expects($this->any())->method('isPlain')->will($this->returnValue(true));
$this->queueMock->expects($this->once())
->method('load')
->will($this->returnSelf());
$this->templateMock->expects($this->any())
->method('isPlain')
->will($this->returnValue(true));
/** @var Store $store */
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->will($this->returnValue(null));
$this->storeManagerMock->expects($this->once())
->method('getDefaultStoreView')
->will($this->returnValue(null));
$store = $this->createPartialMock(Store::class, ['getId']);
$this->storeManager->expects($this->once())->method('getStores')->will($this->returnValue([0 => $store]));
$this->storeManagerMock->expects($this->once())
->method('getStores')
->will($this->returnValue([0 => $store]));
$result = $this->preview->toHtml();
$this->assertEquals('<pre></pre>', $result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,39 @@
use PHPUnit\Framework\TestCase;

/**
* Test for \Magento\Newsletter\Block\Adminhtml\Template\Preview
* @covers \Magento\Newsletter\Block\Adminhtml\Template\Preview
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PreviewTest extends TestCase
{
/** @var Preview */
protected $preview;
private $preview;

/** @var ObjectManagerHelper */
protected $objectManagerHelper;
private $objectManagerHelper;

/** @var \Magento\Newsletter\Model\Template|MockObject */
protected $template;
/** @var Template|MockObject */
private $templateMock;

/** @var SubscriberFactory|MockObject */
protected $subscriberFactory;
private $subscriberFactoryMock;

/** @var State|MockObject */
protected $appState;
private $appStateMock;

/** @var StoreManagerInterface|MockObject */
protected $storeManager;
private $storeManagerMock;

/** @var RequestInterface|MockObject */
protected $request;
private $requestMock;

protected function setUp(): void
{
$this->request = $this->createMock(RequestInterface::class);
$this->appState = $this->createMock(State::class);
$this->storeManager = $this->createMock(StoreManagerInterface::class);
$this->template = $this->createPartialMock(
$this->requestMock = $this->createMock(RequestInterface::class);
$this->appStateMock = $this->createMock(State::class);
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
$this->templateMock = $this->createPartialMock(
Template::class,
[
'setTemplateType',
Expand All @@ -68,8 +69,8 @@ protected function setUp(): void
]
);
$templateFactory = $this->createPartialMock(TemplateFactory::class, ['create']);
$templateFactory->expects($this->once())->method('create')->willReturn($this->template);
$this->subscriberFactory = $this->createPartialMock(
$templateFactory->expects($this->once())->method('create')->willReturn($this->templateMock);
$this->subscriberFactoryMock = $this->createPartialMock(
SubscriberFactory::class,
['create']
);
Expand All @@ -81,32 +82,32 @@ protected function setUp(): void
$this->preview = $this->objectManagerHelper->getObject(
Preview::class,
[
'appState' => $this->appState,
'storeManager' => $this->storeManager,
'request' => $this->request,
'appState' => $this->appStateMock,
'storeManager' => $this->storeManagerMock,
'request' => $this->requestMock,
'templateFactory' => $templateFactory,
'subscriberFactory' => $this->subscriberFactory,
'subscriberFactory' => $this->subscriberFactoryMock,
'escaper' => $escaper
]
);
}

public function testToHtml()
{
$this->request->expects($this->any())->method('getParam')->willReturnMap(
$this->requestMock->expects($this->any())->method('getParam')->willReturnMap(
[
['id', null, 1],
['store', null, 1]
]
);

$this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->template->expects($this->atLeastOnce())->method('revertDesign');
$this->templateMock->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->templateMock->expects($this->atLeastOnce())->method('revertDesign');

$this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')
$this->appStateMock->expects($this->atLeastOnce())->method('emulateAreaCode')
->with(
Template::DEFAULT_DESIGN_AREA,
[$this->template, 'getProcessedTemplate'],
[$this->templateMock, 'getProcessedTemplate'],
[['subscriber' => null]]
)
->willReturn('Processed Template');
Expand All @@ -116,34 +117,34 @@ public function testToHtml()

public function testToHtmlForNewTemplate()
{
$this->request->expects($this->any())->method('getParam')->willReturnMap(
$this->requestMock->expects($this->any())->method('getParam')->willReturnMap(
[
['type', null, TemplateTypesInterface::TYPE_TEXT],
['text', null, 'Processed Template'],
['styles', null, '.class-name{color:red;}']
]
);

$this->template->expects($this->once())->method('setTemplateType')->with(TemplateTypesInterface::TYPE_TEXT)
$this->templateMock->expects($this->once())->method('setTemplateType')->with(TemplateTypesInterface::TYPE_TEXT)
->willReturnSelf();
$this->template->expects($this->once())->method('setTemplateText')->with('Processed Template')
$this->templateMock->expects($this->once())->method('setTemplateText')->with('Processed Template')
->willReturnSelf();
$this->template->expects($this->once())->method('setTemplateStyles')->with('.class-name{color:red;}')
$this->templateMock->expects($this->once())->method('setTemplateStyles')->with('.class-name{color:red;}')
->willReturnSelf();
$this->template->expects($this->atLeastOnce())->method('isPlain')->willReturn(true);
$this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->template->expects($this->atLeastOnce())->method('revertDesign');
$this->templateMock->expects($this->atLeastOnce())->method('isPlain')->willReturn(true);
$this->templateMock->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->templateMock->expects($this->atLeastOnce())->method('revertDesign');

$store = $this->createMock(Store::class);
$store->expects($this->atLeastOnce())->method('getId')->willReturn(1);

$this->storeManager->expects($this->atLeastOnce())->method('getStores')->willReturn([$store]);
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStores')->willReturn([$store]);

$this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')
$this->appStateMock->expects($this->atLeastOnce())->method('emulateAreaCode')
->with(
Template::DEFAULT_DESIGN_AREA,
[
$this->template,
$this->templateMock,
'getProcessedTemplate'
],
[
Expand All @@ -159,7 +160,7 @@ public function testToHtmlForNewTemplate()

public function testToHtmlWithSubscriber()
{
$this->request->expects($this->any())->method('getParam')->willReturnMap(
$this->requestMock->expects($this->any())->method('getParam')->willReturnMap(
[
['id', null, 2],
['store', null, 1],
Expand All @@ -168,16 +169,16 @@ public function testToHtmlWithSubscriber()
);
$subscriber = $this->createMock(Subscriber::class);
$subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf();
$this->subscriberFactory->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);
$this->subscriberFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);

$this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->template->expects($this->atLeastOnce())->method('revertDesign');
$this->templateMock->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
$this->templateMock->expects($this->atLeastOnce())->method('revertDesign');

$this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')
$this->appStateMock->expects($this->atLeastOnce())->method('emulateAreaCode')
->with(
Template::DEFAULT_DESIGN_AREA,
[
$this->template,
$this->templateMock,
'getProcessedTemplate'
],
[
Expand Down
Loading

0 comments on commit c07b96d

Please sign in to comment.