Skip to content

Commit

Permalink
#22447 integration-test-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar65 committed May 7, 2019
1 parent ed86411 commit b8b2458
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 2,576 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<label>Enable PayPal Credit</label>
<comment><![CDATA[PayPal Express Checkout Payflow Edition lets you give customers access to financing through PayPal Credit&#174; - at no additional cost to you.
You get paid up front, even though customers have more time to pay. A pre-integrated payment button lets customers pay quickly with PayPal Credit&#174;.
<a href="https:/www.paypal.com/webapps/mpp/promotional-financing" target="_blank">Learn More</a>]]>
<a href="https://www.paypal.com/webapps/mpp/promotional-financing" target="_blank">Learn More</a>]]>
</comment>
<config_path>payment/payflow_express_bml/active</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Model\Config\Structure\Reader;
declare(strict_types=1);

namespace Magento\Config\Model\Config\Structure\Reader;

use Magento\Config\Model\Config\Structure\Converter;

/**
* Class ConverterStub
* Class ConverterStub used for ReaderTest.
*/
class ConverterStub extends \Magento\Config\Model\Config\Structure\Converter
class ConverterStub extends Converter
{
/**
* Convert dom document wrapper.
*
* @param \DOMDocument $document
* @return array|null
*/
Expand All @@ -20,7 +26,7 @@ public function getArrayData(\DOMDocument $document)
}

/**
* Convert dom document
* Convert dom document.
*
* @param \DOMNode $source
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*
*/
namespace Magento\Widget\Model\Config;
namespace Magento\Config\Model\Config\Structure\Reader;

/**
* @magentoAppArea adminhtml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Model\Config\Structure\Reader;
declare(strict_types=1);

namespace Magento\Config\Model\Config\Structure\Reader;

use Magento\Config\Model\Config\Structure\Reader;

/**
* Class ReaderStub
* Class ReaderStub used for testing protected Reader::_readFiles() method.
*/
class ReaderStub extends \Magento\Config\Model\Config\Structure\Reader
class ReaderStub extends Reader
{
/**
* Wrapper for protected Reader::_readFiles() method.
*
* @param array $fileList
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Config\Model\Config\Structure\Reader;

use Magento\TestFramework\Helper\Bootstrap;
use Magento\Config\Model\Config\SchemaLocator;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Config\Dom;
use Magento\Framework\Config\FileResolverInterface;
use Magento\Framework\Config\ValidationStateInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface;

/**
* Class ReaderTest check Magento\Config\Model\Config\Structure\Reader::_readFiles() method.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Widget\Model\Config\Reader
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $fileResolver;

/**
* Test config location.
*
* @string
*/
const CONFIG = '/dev/tests/integration/testsuite/Magento/Config/Model/Config/Structure/Reader/_files/';

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var Files
*/
private $fileUtility;

/**
* @var ValidationStateInterface
*/
private $validationStateMock;

/**
* @var \Magento\Framework\Config\SchemaLocatorInterface
*/
private $schemaLocatorMock;

/**
* @var FileResolverInterface
*/
private $fileResolverMock;

/**
* @var ReaderStub
*/
private $reader;

/**
* @var ConverterStub
*/
private $converter;

/**
* @var CompilerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $compiler;

/**
* @inheritdoc
*/
public function setUp()
{
$this->fileResolver = $this->getMockForAbstractClass(FileResolverInterface::class);
$objectManager = Bootstrap::getObjectManager();
$this->model = $objectManager->create(
\Magento\Widget\Model\Config\Reader::class,
['fileResolver' => $this->fileResolver]
);
$this->objectManager = Bootstrap::getObjectManager();
$this->fileUtility = Files::init();
$this->fileResolverMock = $this->getMockBuilder(FileResolverInterface::class)
->getMockForAbstractClass();
$this->converter = $this->objectManager->create(ConverterStub::class);

//Isolate test from actual configuration, and leave only sample data.
$this->compiler = $this->getMockBuilder(CompilerInterface::class)
->disableOriginalConstructor()
->setMethods(['compile'])
->getMockForAbstractClass();
}

/**
* The test checks the file structure after processing the nodes responsible for inserting content.
*
* @return void
*/
public function testXmlConvertedConfigurationAndCompereStructure()
{
$this->validationStateMock = $this->getMockBuilder(ValidationStateInterface::class)
->setMethods(['isValidationRequired'])
->getMockForAbstractClass();
$this->validationStateMock->expects($this->atLeastOnce())
->method('isValidationRequired')
->willReturn(false);
$this->schemaLocatorMock = $this->getMockBuilder(SchemaLocator::class)
->disableOriginalConstructor()
->setMethods(['getPerFileSchema'])
->getMock();
$this->reader = $this->objectManager->create(
ReaderStub::class,
[
'fileResolver' => $this->fileResolverMock,
'converter' => $this->converter,
'schemaLocator' => $this->schemaLocatorMock,
'validationState' => $this->validationStateMock,
'fileName' => 'no_existing_file.xml',
'compiler' => $this->compiler,
'domDocumentClass' => Dom::class
]
);
$actual = $this->reader->readFiles(['actual' => $this->getContent()]);

$document = new \DOMDocument();
$document->loadXML($this->getContent());

$expected = $this->converter->getArrayData($document);

$this->assertEquals($expected, $actual);
}

/**
* Get config sample data for test.
*
* @return string
*/
protected function getContent()
{
$files = $this->fileUtility->getFiles([BP . static::CONFIG], 'config.xml');

return file_get_contents(reset($files));
}

/**
* Checks method read() to get correct config.
*
*/
public function testRead()
{
$this->fileResolver->expects($this->once())
->method('get')
->willReturn([file_get_contents(__DIR__ . '/_files/orders_and_returns.xml')]);
$expected = include __DIR__ . '/_files/expectedGlobalArray.php';
$this->assertEquals($expected, $this->model->read('global'));
}

/**
* Checks method _readFiles() to get correct config.
*
*/
public function testReadFile()
{
$file = file_get_contents(__DIR__ . '/_files/orders_and_returns.xml');
$expected = include __DIR__ . '/_files/expectedGlobalArray.php';
$this->assertEquals($expected, $this->model->readFile($file));
}

/**
* Checks method _readFiles() to get correct config with merged configs.
*
*/
public function testMergeCompleteAndPartial()
{
$fileList = [
file_get_contents(__DIR__ . '/_files/catalog_new_products_list.xml'),
file_get_contents(__DIR__ . '/_files/orders_and_returns_customized.xml'),
];
$this->fileResolver->expects($this->once())
->method('get')
->with('widget.xml', 'global')
->willReturn($fileList);
$expected = include __DIR__ . '/_files/expectedMergedArray.php';
$this->assertEquals($expected, $this->model->read('global'));
}
}
Loading

0 comments on commit b8b2458

Please sign in to comment.