-
Notifications
You must be signed in to change notification settings - Fork 283
N°9009 Add phpunit test to GetSelectedModules #792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -559,4 +559,99 @@ private static function GetStep($index) | |
|
|
||
| return $aSteps[$index] ?? null; | ||
| } | ||
|
|
||
| public function ProviderGetSelectedModules() | ||
| { | ||
| return [ | ||
| 'No extension selected' => [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder : do we have other cases with different conditions and same result? How about having test cases with exclusive options ? |
||
| 'aSelected' => [], | ||
| 'aExpectedModules' => [], | ||
| 'aExpectedExtensions' => [], | ||
| ], | ||
| 'One extension selected' => [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independently from the implementation, we should have tests scenarios with multiple extensions selected |
||
| 'aSelected' => ['_0' => '_0'], | ||
| 'aExpectedModules' => ['combodo-sample-module' => true], | ||
| 'aExpectedExtensions' => ['combodo-sample'], | ||
| ], | ||
| ]; | ||
| } | ||
Timmy38 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @dataProvider ProviderGetSelectedModules | ||
| */ | ||
| public function testGetSelectedModules($aSelectedExtensions, $aExpectedModules, $aExpectedExtensions) | ||
| { | ||
| $aExtensionsMapData = [ | ||
| 'combodo-sample' => [ | ||
| 'installed' => false, | ||
| ], | ||
| ]; | ||
| $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, )); | ||
|
||
|
|
||
| //GetSelectedModules | ||
| $aStepInfo = [ | ||
| 'title' => 'Extensions', | ||
| 'description' => '', | ||
| 'banner' => '', | ||
| 'options' => [ | ||
| [ | ||
| 'extension_code' => 'combodo-sample', | ||
| 'title' => 'Sample extension', | ||
| 'description' => '', | ||
| 'more_info' => '', | ||
| 'default' => true, | ||
| 'modules' => [ | ||
| 'combodo-sample-module', | ||
| ], | ||
| 'mandatory' => false, | ||
| 'source_label' => '', | ||
| 'uninstallable' => true, | ||
| 'missing' => false, | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| $aModules = []; | ||
| $aExtensions = []; | ||
| $this->oStep->GetSelectedModules($aStepInfo, $aSelectedExtensions, $aModules, '', '', $aExtensions); | ||
| $this->assertEquals($aExpectedModules, $aModules); | ||
| $this->assertEquals($aExpectedExtensions, $aExtensions); | ||
| } | ||
|
|
||
| public function testGetSelectedModulesShouldThrowAnExceptionWhenAnySelectedExtensionDoesNotHaveAnyAssociatedModules() | ||
| { | ||
| $aExtensionsMapData = [ | ||
| 'combodo-sample' => [ | ||
| 'installed' => false, | ||
| ], | ||
| ]; | ||
| $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, )); | ||
|
||
|
|
||
| //GetSelectedModules | ||
| $aStepInfo = [ | ||
| 'title' => 'Extensions', | ||
| 'description' => '', | ||
| 'banner' => '', | ||
| 'options' => [ | ||
| [ | ||
| 'extension_code' => 'combodo-sample', | ||
| 'title' => 'Sample extension', | ||
| 'description' => '', | ||
| 'more_info' => '', | ||
| 'default' => true, | ||
| 'modules' => [], | ||
| 'mandatory' => false, | ||
| 'source_label' => '', | ||
| 'uninstallable' => true, | ||
| 'missing' => false, | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| $aModules = []; | ||
| $aExtensions = []; | ||
| $this->expectException('Exception'); | ||
Timmy38 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->oStep->GetSelectedModules($aStepInfo, ['_0' => '_0'], $aModules, '', '', $aExtensions); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message 'Setup option does not have any module associated' could be more helpful by including which extension or choice caused the error. Consider adding the extension code or choice title to the error message to help users identify the problematic configuration more easily.