moduleReaderMock = $this->getMockBuilder(Reader::class)
->disableOriginalConstructor()
->getMock();
$this->readFactoryMock = $this->getMockBuilder(ReadFactory::class)
->disableOriginalConstructor()
->getMock();
$this->includeElement = new IncludeElement(
$this->moduleReaderMock,
$this->readFactoryMock
);
}
/**
* @return void
*/
public function testCompileSuccess()
{
$xmlContent = '';
$document = new \DOMDocument();
$document->loadXML($xmlContent);
$compilerMock = $this->getMockBuilder(CompilerInterface::class)
->getMockForAbstractClass();
$processedObjectMock = $this->getMockBuilder(DataObject::class)
->disableOriginalConstructor()
->getMock();
$this->getContentStep();
$compilerMock->expects($this->exactly(2))
->method('compile')
->with($this->isInstanceOf('\DOMElement'), $processedObjectMock, $processedObjectMock);
$this->includeElement->compile(
$compilerMock,
$document->documentElement->firstChild,
$processedObjectMock,
$processedObjectMock
);
$this->assertEquals(
' ',
str_replace(PHP_EOL, '', $document->saveXML())
);
}
public function testCompileException()
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$this->expectExceptionMessage('The "adminhtml/path/to/file.xml" file doesn\'t exist.');
$xmlContent = '';
$document = new \DOMDocument();
$document->loadXML($xmlContent);
$compilerMock = $this->getMockBuilder(CompilerInterface::class)
->getMockForAbstractClass();
$processedObjectMock = $this->getMockBuilder(DataObject::class)
->disableOriginalConstructor()
->getMock();
$this->getContentStep(false);
$compilerMock->expects($this->never())
->method('compile')
->with($this->isInstanceOf('\DOMElement'), $processedObjectMock, $processedObjectMock);
$this->includeElement->compile(
$compilerMock,
$document->documentElement->firstChild,
$processedObjectMock,
$processedObjectMock
);
}
/**
* @param bool $check
*/
protected function getContentStep($check = true)
{
$resultPath = 'adminhtml/path/to/file.xml';
$includeXmlContent = ' ';
$modulesDirectoryMock = $this->getMockBuilder(ReadInterface::class)
->getMockForAbstractClass();
$this->readFactoryMock->expects($this->once())
->method('create')
->willReturn($modulesDirectoryMock);
$this->moduleReaderMock->expects($this->once())
->method('getModuleDir')
->with('etc', 'Module_Name')
->willReturn('path/in/application/module');
$modulesDirectoryMock->expects($this->once())
->method('isExist')
->with($resultPath)
->willReturn($check);
if ($check) {
$modulesDirectoryMock->expects($this->once())
->method('isFile')
->with($resultPath)
->willReturn($check);
$modulesDirectoryMock->expects($this->once())
->method('readFile')
->with($resultPath)
->willReturn($includeXmlContent);
}
}
}