Skip to content

Commit a108dab

Browse files
committed
Fix Module\DirTest and add test for new Resolver functionality
1 parent 0d31f71 commit a108dab

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

lib/internal/Magento/Framework/Module/Dir.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function __construct(Filesystem $filesystem, StringHelper $string, Resolv
5757
public function getDir($moduleName, $type = '')
5858
{
5959
if (null === $path = $this->dirResolver->getModulePath($moduleName)) {
60-
$path = $this->_string->upperCaseWords($moduleName, '_', '/');
60+
$relativePath = $this->_string->upperCaseWords($moduleName, '_', '/');
61+
$path = $this->_modulesDirectory->getAbsolutePath($relativePath);
6162
}
6263

6364
if ($type) {
@@ -67,8 +68,6 @@ public function getDir($moduleName, $type = '')
6768
$path .= '/' . $type;
6869
}
6970

70-
$result = $this->_modulesDirectory->getAbsolutePath($path);
71-
72-
return $result;
71+
return $path;
7372
}
7473
}

lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class DirTest extends \PHPUnit_Framework_TestCase
2727
*/
2828
protected $directoryMock;
2929

30+
/**
31+
* @var \Magento\Framework\Module\Dir\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $dirResolverMock;
34+
3035
protected function setUp()
3136
{
3237
$this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false, false);
@@ -39,8 +44,14 @@ protected function setUp()
3944
false
4045
);
4146
$this->_stringMock = $this->getMock('Magento\Framework\Stdlib\String', [], [], '', false, false);
42-
43-
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
47+
$this->dirResolverMock = $this->getMock(
48+
'Magento\Framework\Module\Dir\ResolverInterface',
49+
[],
50+
[],
51+
'',
52+
false,
53+
false
54+
);
4455

4556
$this->filesystemMock->expects(
4657
$this->once()
@@ -50,11 +61,27 @@ protected function setUp()
5061
$this->returnValue($this->directoryMock)
5162
);
5263

53-
$this->_model = new \Magento\Framework\Module\Dir($this->filesystemMock, $this->_stringMock);
64+
$this->_model = new \Magento\Framework\Module\Dir(
65+
$this->filesystemMock,
66+
$this->_stringMock,
67+
$this->dirResolverMock
68+
);
5469
}
5570

5671
public function testGetDirModuleRoot()
5772
{
73+
$this->dirResolverMock->expects(
74+
$this->once()
75+
)->method(
76+
'getModulePath'
77+
)->with(
78+
'Test_Module'
79+
)->will(
80+
$this->returnValue(null)
81+
);
82+
83+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
84+
5885
$this->directoryMock->expects(
5986
$this->once()
6087
)->method(
@@ -64,20 +91,39 @@ public function testGetDirModuleRoot()
6491
)->will(
6592
$this->returnValue('/Test/Module')
6693
);
94+
6795
$this->assertEquals('/Test/Module', $this->_model->getDir('Test_Module'));
6896
}
6997

98+
public function testGetDirModuleRootFromResolver()
99+
{
100+
$this->dirResolverMock->expects(
101+
$this->once()
102+
)->method(
103+
'getModulePath'
104+
)->with(
105+
'Test_Module2'
106+
)->will(
107+
$this->returnValue('/path/to/module')
108+
);
109+
110+
$this->assertEquals('/path/to/module', $this->_model->getDir('Test_Module2'));
111+
}
112+
70113
public function testGetDirModuleSubDir()
71114
{
115+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
116+
72117
$this->directoryMock->expects(
73118
$this->once()
74119
)->method(
75120
'getAbsolutePath'
76121
)->with(
77-
'Test/Module/etc'
122+
'Test/Module'
78123
)->will(
79-
$this->returnValue('/Test/Module/etc')
124+
$this->returnValue('/Test/Module')
80125
);
126+
81127
$this->assertEquals('/Test/Module/etc', $this->_model->getDir('Test_Module', 'etc'));
82128
}
83129

@@ -87,6 +133,8 @@ public function testGetDirModuleSubDir()
87133
*/
88134
public function testGetDirModuleSubDirUnknown()
89135
{
136+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
137+
90138
$this->_model->getDir('Test_Module', 'unknown');
91139
}
92140
}

0 commit comments

Comments
 (0)