20 private $themePackageInfo;
25 private $componentRegistrar;
30 private $dirReadFactory;
33 private $serializerMock;
37 $this->componentRegistrar = $this->createMock(\
Magento\Framework\Component\ComponentRegistrar::class);
38 $this->dirRead = $this->createMock(\
Magento\Framework\
Filesystem\Directory\Read::class);
39 $this->dirReadFactory = $this->createMock(\
Magento\Framework\
Filesystem\Directory\ReadFactory::class);
40 $this->dirReadFactory->expects($this->any())->method(
'create')->willReturn($this->dirRead);
41 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)
44 $this->componentRegistrar,
45 $this->dirReadFactory,
52 $themeFileContents =
'{"name": "package"}';
53 $this->componentRegistrar->expects($this->once())->method(
'getPath')->willReturn(
'path/to/A');
54 $this->dirRead->expects($this->once())->method(
'isExist')->with(
'composer.json')->willReturn(
true);
55 $this->dirRead->expects($this->once())
57 ->with(
'composer.json')
58 ->willReturn($themeFileContents);
59 $this->serializerMock->expects($this->once())
60 ->method(
'unserialize')
61 ->willReturn(json_decode($themeFileContents,
true));
62 $this->assertEquals(
'package', $this->themePackageInfo->getPackageName(
'themeA'));
67 $this->componentRegistrar->expects($this->once())->method(
'getPath')->willReturn(
'path/to/A');
68 $this->dirRead->expects($this->once())->method(
'isExist')->with(
'composer.json')->willReturn(
false);
69 $this->dirRead->expects($this->never())->method(
'readFile')->with(
'composer.json');
70 $this->assertEquals(
'', $this->themePackageInfo->getPackageName(
'themeA'));
75 $themeFileContents =
'{"name": "package"}';
76 $this->componentRegistrar->expects($this->once())->method(
'getPaths')->willReturn([
'themeA' =>
'path/to/A']);
77 $this->dirRead->expects($this->once())->method(
'isExist')->willReturn(
true);
78 $this->dirRead->expects($this->once())->method(
'readFile')->willReturn($themeFileContents);
79 $this->serializerMock->expects($this->once())
80 ->method(
'unserialize')
81 ->willReturn(json_decode($themeFileContents,
true));
82 $this->assertEquals(
'themeA', $this->themePackageInfo->getFullThemePath(
'package'));
84 $this->assertEquals(
'themeA', $this->themePackageInfo->getFullThemePath(
'package'));
89 $this->componentRegistrar->expects($this->once())->method(
'getPaths')->willReturn([
'themeA' =>
'path/to/A']);
90 $this->dirRead->expects($this->once())->method(
'isExist')->willReturn(
true);
91 $this->dirRead->expects($this->once())->method(
'readFile')->willReturn(
'{"name": "package"}');
92 $this->assertEquals(
'', $this->themePackageInfo->getFullThemePath(
'package-other'));
97 $this->componentRegistrar->expects($this->once())->method(
'getPath')->willReturn(
'path/to/A');
98 $this->dirRead->expects($this->once())->method(
'isExist')->willReturn(
true);
99 $this->dirRead->expects($this->once())->method(
'readFile')->willReturn(
'{"name": }');
100 $this->serializerMock->expects($this->once())
101 ->method(
'unserialize')
103 $this->assertEquals(
'', $this->themePackageInfo->getPackageName(
'themeA'));
testGetPackageNameNonExist()
testGetPackageNameInvalidJson()
testGetFullThemePathNonExist()