|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace tests\unit\Magento\FunctionalTestFramework\Util; |
| 9 | + |
| 10 | +use Exception; |
| 11 | +use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; |
| 12 | +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; |
| 13 | +use tests\unit\Util\MagentoTestCase; |
| 14 | +use tests\unit\Util\TestLoggingUtil; |
| 15 | +use Magento\FunctionalTestingFramework\StaticCheck\UnusedEntityCheck; |
| 16 | +use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil; |
| 17 | + |
| 18 | +class UnusedEntityCheckTest extends MagentoTestCase |
| 19 | +{ |
| 20 | + |
| 21 | + public function testUnusedEntityFilesCheck() |
| 22 | + { |
| 23 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 24 | + $result = $unusedEntityCheck->unusedEntities(); |
| 25 | + $this->assertIsArray($result); |
| 26 | + } |
| 27 | + |
| 28 | + public function testUnusedActiongroupFiles() |
| 29 | + { |
| 30 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 31 | + $domDocument = new \DOMDocument(); |
| 32 | + $actionGroupFiles = ['DeprecationCheckActionGroup' => |
| 33 | + '/verification/DeprecationCheckModule/ActionGroup/DeprecationCheckActionGroup.xml', |
| 34 | + 'ActionGroupWithMultiplePausesActionGroup'=> |
| 35 | + '/verification/PauseCheckModule/ActionGroup/ActionGroupWithMultiplePausesActionGroup.xml', |
| 36 | + 'ActionGroupWithNoPauseActionGroup'=> |
| 37 | + '/verification/PauseCheckModule/ActionGroup/ActionGroupWithNoPauseActionGroup.xml']; |
| 38 | + $result = $unusedEntityCheck->unusedActionEntity($domDocument, [], [], $actionGroupFiles, []); |
| 39 | + $this->assertIsArray($result); |
| 40 | + $this->assertCount(3, $result); |
| 41 | + } |
| 42 | + |
| 43 | + public function testUnusedActiongroupFilesReturnedWhenActionXmlFilesAreNotEmpty() |
| 44 | + { |
| 45 | + $this->scriptUtil = new ScriptUtil(); |
| 46 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 47 | + $domDocument = new \DOMDocument(); |
| 48 | + $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 49 | + $actionGroupXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, "ActionGroup"); |
| 50 | + $actionGroupFiles = ['DeprecationCheckActionGroup' => |
| 51 | + '/verification/DeprecationCheckModule/ActionGroup/DeprecationCheckActionGroup.xml', |
| 52 | + 'ActionGroupWithMultiplePausesActionGroup'=> |
| 53 | + '/verification/PauseCheckModule/ActionGroup/ActionGroupWithMultiplePausesActionGroup.xml', |
| 54 | + 'ActionGroupWithNoPauseActionGroup' => |
| 55 | + '/verification/PauseCheckModule/ActionGroup/ActionGroupWithNoPauseActionGroup.xml']; |
| 56 | + $result = $unusedEntityCheck->unusedActionEntity( |
| 57 | + $domDocument, |
| 58 | + $actionGroupXmlFiles, |
| 59 | + [], |
| 60 | + $actionGroupFiles, |
| 61 | + [] |
| 62 | + ); |
| 63 | + $this->assertIsArray($result); |
| 64 | + $this->assertCount(3, $result); |
| 65 | + } |
| 66 | + |
| 67 | + public function testUnusedSectionFiles() |
| 68 | + { |
| 69 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 70 | + $domDocument = new \DOMDocument(); |
| 71 | + $section = [ |
| 72 | + 'DeprecationCheckSection' => '/verification/DeprecationCheckModule/Section/DeprecationCheckSection.xml', |
| 73 | + 'DeprecatedSection' => '/verification/TestModule/Section/DeprecatedSection.xml', |
| 74 | + 'LocatorFunctionSection' => '/verification/TestModule/Section/LocatorFunctionSection.xml', |
| 75 | + 'SampleSection' => '/verification/TestModuleMerged/Section/MergeSection.xml' |
| 76 | + ]; |
| 77 | + $result=$unusedEntityCheck->unusedSectionEntity($domDocument, [], [], [], $section, []); |
| 78 | + $this->assertIsArray($result); |
| 79 | + $this->assertCount(4, $result); |
| 80 | + } |
| 81 | + |
| 82 | + public function testUnusedSectionFilesReturnedWhenSectionXmlFilesAreNotEmpty() |
| 83 | + { |
| 84 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 85 | + $this->scriptUtil = new ScriptUtil(); |
| 86 | + $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 87 | + $sectionXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, "Section"); |
| 88 | + |
| 89 | + $domDocument = new \DOMDocument(); |
| 90 | + $section = [ |
| 91 | + 'DeprecationCheckSection' => '/verification/DeprecationCheckModule/Section/DeprecationCheckSection.xml', |
| 92 | + 'DeprecatedSection' => '/verification/TestModule/Section/DeprecatedSection.xml', |
| 93 | + 'LocatorFunctionSection' => '/verification/TestModule/Section/LocatorFunctionSection.xml', |
| 94 | + 'SampleSection' => '/verification/TestModuleMerged/Section/MergeSection.xml' |
| 95 | + ]; |
| 96 | + $result = $unusedEntityCheck->unusedSectionEntity($domDocument, $sectionXmlFiles, [], [], $section, []); |
| 97 | + $this->assertIsArray($result); |
| 98 | + $this->assertCount(4, $result); |
| 99 | + } |
| 100 | + |
| 101 | + public function testUnusedPageFiles() |
| 102 | + { |
| 103 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 104 | + $domDocument = new \DOMDocument(); |
| 105 | + $page = [ |
| 106 | + 'DeprecationCheckPage' => '/verification/DeprecationCheckModule/Page/DeprecationCheckPage.xml', |
| 107 | + 'DeprecatedPage' => '/verification/TestModule/Page/DeprecatedPage.xml', |
| 108 | + 'AdminOneParamPage' => '/verification/TestModule/Page/SamplePage/AdminOneParamPage.xml', |
| 109 | + 'AdminPage' => '/verification/TestModule/Page/SamplePage/AdminPage.xml', |
| 110 | + 'ExternalPage' => '/verification/TestModule/Page/SamplePage/ExternalPage.xml', |
| 111 | + 'NoParamPage' => '/verification/TestModule/Page/SamplePage/NoParamPage.xml' |
| 112 | + ]; |
| 113 | + $result = $unusedEntityCheck->unusedPageEntity($domDocument, [], [], $page, []); |
| 114 | + $this->assertIsArray($result); |
| 115 | + $this->assertCount(6, $result); |
| 116 | + } |
| 117 | + |
| 118 | + public function testUnusedPageFilesReturnedWhenPageXmlFilesPassedAreNotEmpty() |
| 119 | + { |
| 120 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 121 | + $domDocument = new \DOMDocument(); |
| 122 | + $this->scriptUtil = new ScriptUtil(); |
| 123 | + $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 124 | + $pageXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, "Page"); |
| 125 | + $page = [ |
| 126 | + 'DeprecationCheckPage' => '/verification/DeprecationCheckModule/Page/DeprecationCheckPage.xml', |
| 127 | + 'DeprecatedPage' => '/verification/TestModule/Page/DeprecatedPage.xml', |
| 128 | + 'AdminOneParamPage' => '/verification/TestModule/Page/SamplePage/AdminOneParamPage.xml', |
| 129 | + 'AdminPage' => '/verification/TestModule/Page/SamplePage/AdminPage.xml', |
| 130 | + 'ExternalPage' => '/verification/TestModule/Page/SamplePage/ExternalPage.xml', |
| 131 | + 'NoParamPage' => '/verification/TestModule/Page/SamplePage/NoParamPage.xml' |
| 132 | + ]; |
| 133 | + $result = $unusedEntityCheck->unusedPageEntity($domDocument, $pageXmlFiles, [], $page, []); |
| 134 | + $this->assertIsArray($result); |
| 135 | + $this->assertCount(6, $result); |
| 136 | + } |
| 137 | + |
| 138 | + public function testUnusedData() |
| 139 | + { |
| 140 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 141 | + $domDocument = new \DOMDocument(); |
| 142 | + $data = [ |
| 143 | + "simpleData" => |
| 144 | + [ |
| 145 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 146 | + ], |
| 147 | + |
| 148 | + "uniqueData" => [ |
| 149 | + |
| 150 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 151 | + ], |
| 152 | + |
| 153 | + "offset"=> |
| 154 | + [ |
| 155 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 156 | + ] |
| 157 | + ]; |
| 158 | + $result=$unusedEntityCheck->unusedPageEntity($domDocument, [], [], $data, []); |
| 159 | + $this->assertIsArray($result); |
| 160 | + $this->assertCount(3, $result); |
| 161 | + } |
| 162 | + |
| 163 | + public function testUnusedDataReturnedWhenCreateDataEntityAreNotEmpty() |
| 164 | + { |
| 165 | + $unusedEntityCheck = new UnusedEntityCheck(); |
| 166 | + $domDocument = new \DOMDocument(); |
| 167 | + $this->scriptUtil = new ScriptUtil(); |
| 168 | + $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 169 | + $dataXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, "Data"); |
| 170 | + $data = [ |
| 171 | + "simpleData" => |
| 172 | + [ |
| 173 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 174 | + ], |
| 175 | + |
| 176 | + "uniqueData" => [ |
| 177 | + |
| 178 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 179 | + ], |
| 180 | + |
| 181 | + "offset" => |
| 182 | + [ |
| 183 | + "dataFilePath" => "/verification/TestModule/Data/ReplacementData.xml" |
| 184 | + ] |
| 185 | + ]; |
| 186 | + $result = $unusedEntityCheck->unusedPageEntity($domDocument, $dataXmlFiles, [], $data, []); |
| 187 | + $this->assertIsArray($result); |
| 188 | + $this->assertCount(3, $result); |
| 189 | + } |
| 190 | +} |
0 commit comments