Skip to content

Commit 2286434

Browse files
ENGCOM-6200: Fix module name identification in AbstractBlock #25318
2 parents 3ff6de7 + d0ed7a4 commit 2286434

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* Marked as public API because it is actively used now.
1818
*
19+
* phpcs:disable Magento2.Classes.AbstractApi
1920
* @api
2021
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
2122
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
@@ -244,6 +245,7 @@ public function getRequest()
244245
* Please override this one instead of overriding real __construct constructor
245246
*
246247
* @return void
248+
* phpcs:disable Magento2.CodeAnalysis.EmptyBlock
247249
*/
248250
protected function _construct()
249251
{
@@ -439,9 +441,9 @@ public function unsetChild($alias)
439441
*/
440442
public function unsetCallChild($alias, $callback, $result, $params)
441443
{
444+
$args = func_get_args();
442445
$child = $this->getChildBlock($alias);
443446
if ($child) {
444-
$args = func_get_args();
445447
$alias = array_shift($args);
446448
$callback = array_shift($args);
447449
$result = (string)array_shift($args);
@@ -874,7 +876,7 @@ public static function extractModuleName($className)
874876
$namespace = substr(
875877
$className,
876878
0,
877-
strpos($className, '\\' . 'Block')
879+
strpos($className, '\\' . 'Block' . '\\')
878880
);
879881
return str_replace('\\', '_', $namespace);
880882
}

lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,30 @@ public function getCacheLifetimeDataProvider()
325325
],
326326
];
327327
}
328+
329+
/**
330+
* @return void
331+
*/
332+
public function testExtractModuleName()
333+
{
334+
$blockClassNames = $this->getPossibleBlockClassNames();
335+
336+
foreach ($blockClassNames as $expectedModuleName => $className) {
337+
$extractedModuleName = $this->block->extractModuleName($className);
338+
$this->assertSame($expectedModuleName, $extractedModuleName);
339+
}
340+
}
341+
342+
/**
343+
* @return array
344+
*/
345+
private function getPossibleBlockClassNames()
346+
{
347+
return [
348+
'Vendor_Module' => 'Vendor\Module\Block\Class',
349+
'Vendor_ModuleBlock' => 'Vendor\ModuleBlock\Block\Class',
350+
'Vendor_BlockModule' => 'Vendor\BlockModule\Block\Class',
351+
'Vendor_CustomBlockModule' => 'Vendor\CustomBlockModule\Block\Class',
352+
];
353+
}
328354
}

0 commit comments

Comments
 (0)