9 use \Magento\Framework\Module\Status;
32 private $conflictChecker;
37 private $dependencyChecker;
46 $this->loader = $this->createMock(\
Magento\Framework\Module\
ModuleList\Loader::class);
47 $this->moduleList = $this->createMock(\
Magento\Framework\Module\ModuleList::class);
49 $this->conflictChecker = $this->createMock(\
Magento\Framework\Module\ConflictChecker::class);
50 $this->dependencyChecker = $this->createMock(\
Magento\Framework\Module\DependencyChecker::class);
51 $this->
object =
new Status(
55 $this->conflictChecker,
56 $this->dependencyChecker
62 $this->conflictChecker->expects($this->once())
63 ->method(
'checkConflictsWhenEnableModules')
64 ->will($this->returnValue([
'Module_Foo' => [],
'Module_Bar' => []]));
65 $this->dependencyChecker->expects($this->once())
66 ->method(
'checkDependenciesWhenEnableModules')
67 ->will($this->returnValue([
'Module_Foo' => [],
'Module_Bar' => []]));
68 $result = $this->
object->checkConstraints(
70 [
'Module_Foo' =>
'',
'Module_Bar' =>
''],
71 [
'Module_baz',
'Module_quz']
73 $this->assertEquals([],
$result);
78 $this->conflictChecker->expects($this->once())
79 ->method(
'checkConflictsWhenEnableModules')
80 ->will($this->returnValue([
'Module_Foo' => [
'Module_Bar'],
'Module_Bar' => [
'Module_Foo']]));
81 $this->dependencyChecker->expects($this->once())
82 ->method(
'checkDependenciesWhenEnableModules')
83 ->will($this->returnValue(
85 'Module_Foo' => [
'Module_Baz' => [
'Module_Foo',
'Module_Baz']],
86 'Module_Bar' => [
'Module_Baz' => [
'Module_Bar',
'Module_Baz']],
89 $result = $this->
object->checkConstraints(
true, [
'Module_Foo' =>
'',
'Module_Bar' =>
''], [],
false);
91 'Cannot enable Module_Foo because it depends on disabled modules:',
92 "Module_Baz: Module_Foo->Module_Baz",
93 'Cannot enable Module_Bar because it depends on disabled modules:',
94 "Module_Baz: Module_Bar->Module_Baz",
95 'Cannot enable Module_Foo because it conflicts with other modules:',
97 'Cannot enable Module_Bar because it conflicts with other modules:',
100 $this->assertEquals($expect,
$result);
105 $this->conflictChecker->expects($this->once())
106 ->method(
'checkConflictsWhenEnableModules')
107 ->will($this->returnValue([
'Module_Foo' => [
'Module_Bar'],
'Module_Bar' => [
'Module_Foo']]));
108 $this->dependencyChecker->expects($this->once())
109 ->method(
'checkDependenciesWhenEnableModules')
110 ->will($this->returnValue(
112 'Module_Foo' => [
'Module_Baz' => [
'Module_Foo',
'Module_Baz']],
113 'Module_Bar' => [
'Module_Baz' => [
'Module_Bar',
'Module_Baz']],
116 $result = $this->
object->checkConstraints(
true, [
'Module_Foo' =>
'',
'Module_Bar' =>
''], [],
true);
118 'Cannot enable Module_Foo',
119 'Cannot enable Module_Bar',
120 'Cannot enable Module_Foo because it conflicts with other modules:',
122 'Cannot enable Module_Bar because it conflicts with other modules:',
125 $this->assertEquals($expect,
$result);
130 $this->dependencyChecker->expects($this->once())
131 ->method(
'checkDependenciesWhenDisableModules')
132 ->will($this->returnValue([
'Module_Foo' => [],
'Module_Bar' => []]));
133 $result = $this->
object->checkConstraints(
false, [
'Module_Foo' =>
'',
'Module_Bar' =>
'']);
134 $this->assertEquals([],
$result);
139 $this->dependencyChecker->expects($this->once())
140 ->method(
'checkDependenciesWhenDisableModules')
141 ->will($this->returnValue(
143 'Module_Foo' => [
'Module_Baz' => [
'Module_Baz',
'Module_Foo']],
144 'Module_Bar' => [
'Module_Baz' => [
'Module_Baz',
'Module_Bar']],
147 $result = $this->
object->checkConstraints(
false, [
'Module_Foo' =>
'',
'Module_Bar' =>
'']);
149 'Cannot disable Module_Foo because modules depend on it:',
150 "Module_Baz: Module_Baz->Module_Foo",
151 'Cannot disable Module_Bar because modules depend on it:',
152 "Module_Baz: Module_Baz->Module_Bar",
154 $this->assertEquals($expect,
$result);
159 $modules = [
'Module_Foo' =>
'',
'Module_Bar' =>
'',
'Module_Baz' =>
''];
160 $this->loader->expects($this->once())->method(
'load')->willReturn($modules);
161 $this->moduleList->expects($this->at(0))->method(
'has')->with(
'Module_Foo')->willReturn(
false);
162 $this->moduleList->expects($this->at(1))->method(
'has')->with(
'Module_Bar')->willReturn(
false);
163 $this->moduleList->expects($this->at(2))->method(
'has')->with(
'Module_Baz')->willReturn(
false);
164 $expectedModules = [
'Module_Foo' => 1,
'Module_Bar' => 1,
'Module_Baz' => 0];
165 $this->writer->expects($this->once())->method(
'saveConfig')
167 $this->
object->setIsEnabled(
true, [
'Module_Foo',
'Module_Bar']);
176 $modules = [
'Module_Foo' =>
'',
'Module_Bar' =>
''];
177 $this->loader->expects($this->once())->method(
'load')->willReturn($modules);
178 $this->
object->setIsEnabled(
true, [
'Module_Baz']);
191 $modules = [
'Module_Foo' =>
'',
'Module_Bar' =>
'',
'Module_Baz' =>
''];
192 $this->loader->expects($this->once())->method(
'load')->willReturn($modules);
193 $this->moduleList->expects($this->at(0))->method(
'has')->with(
'Module_Foo')->willReturn($firstEnabled);
194 $this->moduleList->expects($this->at(1))->method(
'has')->with(
'Module_Bar')->willReturn($secondEnabled);
195 $this->moduleList->expects($this->at(2))->method(
'has')->with(
'Module_Baz')->willReturn($thirdEnabled);
196 $result = $this->
object->getModulesToChange($isEnabled, [
'Module_Foo',
'Module_Bar',
'Module_Baz']);
197 $this->assertEquals($expected,
$result);
206 [
true,
true,
true,
true, []],
207 [
true,
true,
false,
true, [
'Module_Baz']],
208 [
true,
false,
true,
true, [
'Module_Bar']],
209 [
true,
false,
false,
true, [
'Module_Bar',
'Module_Baz']],
210 [
false,
false,
false,
true, [
'Module_Foo',
'Module_Bar',
'Module_Baz']],
211 [
true,
false,
false,
false, [
'Module_Foo']],
212 [
false,
true,
false,
false, [
'Module_Bar']],
213 [
false,
true,
true,
false, [
'Module_Bar',
'Module_Baz']],
214 [
true,
true,
true,
false, [
'Module_Foo',
'Module_Bar',
'Module_Baz']],
getModulesToChangeDataProvider()
testCheckConstraintsEnableAllowed()
testSetIsEnabledUnknown()
testCheckConstraintsEnableNotAllowedWithPrettyMsg()
testCheckConstraintsEnableNotAllowed()
testGetModulesToChange($firstEnabled, $secondEnabled, $thirdEnabled, $isEnabled, $expected)
testCheckConstraintsDisableNotAllowed()
testCheckConstraintsDisableAllowed()