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
…onfigurableProduct
  • Loading branch information
lbajsarowicz committed Apr 23, 2020
2 parents 868d898 + 0537aa9 commit 9ff82b8
Show file tree
Hide file tree
Showing 65 changed files with 1,234 additions and 734 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

namespace Magento\Cms\Model\Wysiwyg\Gallery;

use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;

/**
* @inheritdoc
*/
class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
{
/**
Expand All @@ -30,26 +35,34 @@ class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigPro
*/
private $currentTreePath;

/**
* @var OpednDialogUrl
*/
private $openDialogUrl;

/**
* @param \Magento\Backend\Model\UrlInterface $backendUrl
* @param \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper
* @param OpenDialogUrl $openDialogUrl
* @param array $windowSize
* @param string|null $currentTreePath
*/
public function __construct(
\Magento\Backend\Model\UrlInterface $backendUrl,
\Magento\Cms\Helper\Wysiwyg\Images $imagesHelper,
OpenDialogUrl $openDialogUrl,
array $windowSize = [],
$currentTreePath = null
) {
$this->backendUrl = $backendUrl;
$this->imagesHelper = $imagesHelper;
$this->openDialogUrl = $openDialogUrl;
$this->windowSize = $windowSize;
$this->currentTreePath = $currentTreePath;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
{
Expand All @@ -72,7 +85,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
[
'add_images' => true,
'files_browser_window_url' => $this->backendUrl->getUrl(
'cms/wysiwyg_images/index',
$this->openDialogUrl->get(),
$fileBrowserUrlParams
),
'files_browser_window_width' => $this->windowSize['width'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminDisableWYSIWYGActionGroup">
<annotations>
<description>Runs bin/magento command to disable WYSIWYG</description>
</annotations>

<magentoCLI stepKey="disableWYSIWYG" command="config:set cms/wysiwyg/enabled disabled"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnableWYSIWYGActionGroup">
<annotations>
<description>Runs bin/magento command to enable WYSIWYG</description>
</annotations>

<magentoCLI stepKey="enableWYSIWYG" command="config:set cms/wysiwyg/enabled enabled"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<waitForPageLoad stepKey="waitForPageLoad1"/>
<see selector="{{StorefrontCategoryMainSection.CategoryTitle}}" userInput="{{category.name_lwr}}" stepKey="assertCategoryOnStorefront"/>
<seeInTitle userInput="{{category.name}}" stepKey="seeCategoryNameInTitle"/>
<see selector="{{StorefrontCMSPageSection.mainContent}}" userInput="{{text}}" stepKey="seeAssertTextInMainContent"/>
<see userInput="{{text}}" stepKey="seeAssertTextInMainContent"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
<suite name="WYSIWYGDisabledSuite">
<before>
<magentoCLI stepKey="disableWYSYWYG" command="config:set cms/wysiwyg/enabled disabled" />
<actionGroup ref="AdminDisableWYSIWYGActionGroup" stepKey="disableWYSYWYG" />
</before>
<include>
<group name="WYSIWYGDisabled"/>
Expand All @@ -17,7 +17,7 @@
<group name="skip"/>
</exclude>
<after>
<magentoCLI stepKey="disableWYSYWYG" command="config:set cms/wysiwyg/enabled enabled" />
<actionGroup ref="AdminEnableWYSIWYGActionGroup" stepKey="disableWYSYWYG" />
</after>
</suite>
</suites>
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
Loading

0 comments on commit 9ff82b8

Please sign in to comment.