Skip to content

Commit 5afe38c

Browse files
authored
Merge branch '2.4-develop' into graphql-api-enhancements
2 parents 6439ec9 + 08f6eee commit 5afe38c

File tree

509 files changed

+20989
-13241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

509 files changed

+20989
-13241
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Helper;
9+
10+
use Magento\Backend\Block\Widget\Button;
11+
12+
/**
13+
* Test helper for Button class with custom methods
14+
*/
15+
class ButtonTestHelper extends Button
16+
{
17+
/**
18+
* @var array
19+
*/
20+
private $data = [];
21+
22+
/**
23+
* Skip parent constructor to avoid dependencies
24+
*/
25+
public function __construct()
26+
{
27+
// Skip parent constructor - clean initialization
28+
$this->data = [];
29+
}
30+
31+
/**
32+
* Custom isAllowed method for testing
33+
*
34+
* @param string|null $resource
35+
* @return bool
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
37+
*/
38+
public function isAllowed($resource = null): bool
39+
{
40+
return $this->data['is_allowed'] ?? true;
41+
}
42+
43+
/**
44+
* Set is allowed for testing
45+
*
46+
* @param bool $isAllowed
47+
* @return self
48+
*/
49+
public function setIsAllowed(bool $isAllowed): self
50+
{
51+
$this->data['is_allowed'] = $isAllowed;
52+
return $this;
53+
}
54+
55+
/**
56+
* Override getAuthorization method
57+
*
58+
* @return mixed
59+
*/
60+
public function getAuthorization()
61+
{
62+
return $this->data['authorization'] ?? null;
63+
}
64+
65+
/**
66+
* Set authorization for testing
67+
*
68+
* @param mixed $authorization
69+
* @return self
70+
*/
71+
public function setAuthorization($authorization): self
72+
{
73+
$this->data['authorization'] = $authorization;
74+
return $this;
75+
}
76+
77+
/**
78+
* Override toHtml method
79+
*
80+
* @return string
81+
*/
82+
public function toHtml(): string
83+
{
84+
return $this->data['html'] ?? '';
85+
}
86+
87+
/**
88+
* Set HTML output for testing
89+
*
90+
* @param string $html
91+
* @return self
92+
*/
93+
public function setHtml(string $html): self
94+
{
95+
$this->data['html'] = $html;
96+
return $this;
97+
}
98+
}

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/ExtendTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ class ExtendTest extends TestCase
3535

3636
protected function setUp(): void
3737
{
38-
$this->registry = $this->getMockBuilder(Registry::class)
39-
->disableOriginalConstructor()
40-
->getMock();
41-
$this->formFactory = $this->getMockBuilder(
38+
$this->registry = $this->createMock(Registry::class);
39+
$this->formFactory = $this->createMock(
4240
FormFactory::class
43-
)->disableOriginalConstructor()
44-
->getMock();
41+
);
4542
$this->objectManagerHelper = new ObjectManager($this);
4643
$objects = [
4744
[
@@ -65,9 +62,7 @@ protected function setUp(): void
6562
*/
6663
public function getProduct()
6764
{
68-
$product = $this->getMockBuilder(Product::class)
69-
->disableOriginalConstructor()
70-
->getMock();
65+
$product = $this->createMock(Product::class);
7166
$this->registry->expects($this->once())
7267
->method('registry')
7368
->with('product')
@@ -80,9 +75,7 @@ public function getProduct()
8075
public function testGetExtendedElement()
8176
{
8277
$switchAttributeCode = 'test_code';
83-
$form = $this->getMockBuilder(Form::class)
84-
->disableOriginalConstructor()
85-
->getMock();
78+
$form = $this->createMock(Form::class);
8679
$hasKey = new ArrayHasKey('value');
8780
$form->expects($this->once())->method('addField')->with(
8881
$switchAttributeCode,

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/OptionTest.php

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,35 @@
99

1010
use Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option;
1111
use Magento\Framework\DataObject;
12+
use Magento\Framework\View\Element\AbstractBlock;
13+
use Magento\Framework\View\LayoutInterface;
14+
use PHPUnit\Framework\MockObject\Exception;
1215
use PHPUnit\Framework\TestCase;
1316

1417
class OptionTest extends TestCase
1518
{
19+
/**
20+
* @return void
21+
* @throws Exception
22+
*/
1623
public function testGetAddButtonId()
1724
{
1825
$button = new DataObject();
26+
$button->setId(42);
1927

20-
$itemsBlock = $this->getMockBuilder(DataObject::class)
21-
->addMethods(['getChildBlock'])
22-
->disableOriginalConstructor()
23-
->getMock();
24-
$itemsBlock->expects(
25-
$this->atLeastOnce()
26-
)->method(
27-
'getChildBlock'
28-
)->with(
29-
'add_button'
30-
)->willReturn(
31-
$button
32-
);
28+
$itemsBlock = $this->createMock(AbstractBlock::class);
29+
$itemsBlock->method('getChildBlock')->with('add_button')->willReturn($button);
3330

34-
$layout = $this->getMockBuilder(DataObject::class)
35-
->addMethods(['getBlock'])
36-
->disableOriginalConstructor()
37-
->getMock();
38-
$layout->expects(
39-
$this->atLeastOnce()
40-
)->method(
41-
'getBlock'
42-
)->with(
43-
'admin.product.bundle.items'
44-
)->willReturn(
45-
$itemsBlock
46-
);
31+
$layout = $this->createMock(LayoutInterface::class);
32+
$layout->method('getBlock')->with('admin.product.bundle.items')->willReturn($itemsBlock);
4733

4834
$block = $this->createPartialMock(
4935
Option::class,
5036
['getLayout']
5137
);
5238
$block->expects($this->atLeastOnce())->method('getLayout')->willReturn($layout);
5339

54-
$this->assertNotEquals(42, $block->getAddButtonId());
55-
$button->setId(42);
40+
// Test that the button ID is correctly retrieved
5641
$this->assertEquals(42, $block->getAddButtonId());
5742
}
5843
}

0 commit comments

Comments
 (0)