Skip to content

Commit 5f69036

Browse files
url escape test coverage
1 parent d2f3466 commit 5f69036

File tree

1 file changed

+63
-30
lines changed
  • dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main

1 file changed

+63
-30
lines changed

dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/LayoutTest.php

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,95 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main;
79

10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\Escaper;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Framework\View\DesignInterface;
15+
use Magento\Framework\View\LayoutInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\Widget\Model\Widget\Instance;
18+
use PHPUnit\Framework\TestCase;
19+
820
/**
921
* @magentoAppArea adminhtml
1022
*/
11-
class LayoutTest extends \PHPUnit\Framework\TestCase
23+
class LayoutTest extends TestCase
1224
{
1325
/**
14-
* @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main\Layout
26+
* @var ObjectManagerInterface
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @var Layout
1532
*/
16-
protected $_block;
33+
private $block;
1734

35+
/**
36+
* @inheritDoc
37+
*/
1838
protected function setUp(): void
1939
{
20-
parent::setUp();
40+
$this->objectManager = Bootstrap::getObjectManager();
2141

22-
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
23-
\Magento\Framework\View\LayoutInterface::class
24-
)->createBlock(
25-
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main\Layout::class,
26-
'',
27-
[
28-
'data' => [
29-
'widget_instance' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
30-
\Magento\Widget\Model\Widget\Instance::class
31-
),
42+
$this->block = $this->objectManager->get(LayoutInterface::class)
43+
->createBlock(
44+
Layout::class,
45+
'',
46+
[
47+
'data' => [
48+
'widget_instance' => $this->objectManager->create(Instance::class),
49+
],
3250
]
33-
]
34-
);
35-
$this->_block->setLayout(
36-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
37-
\Magento\Framework\View\LayoutInterface::class
38-
)
39-
);
51+
);
52+
$this->block->setLayout($this->objectManager->get(LayoutInterface::class));
4053
}
4154

4255
/**
4356
* @magentoAppIsolation enabled
4457
*/
4558
public function testGetLayoutsChooser()
4659
{
47-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
48-
\Magento\Framework\App\State::class
49-
)->setAreaCode(
50-
\Magento\Framework\App\Area::AREA_FRONTEND
51-
);
52-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
53-
\Magento\Framework\View\DesignInterface::class
54-
)->setDefaultDesignTheme();
60+
$this->objectManager->get(State::class)
61+
->setAreaCode(Area::AREA_FRONTEND);
62+
$this->objectManager->get(DesignInterface::class)
63+
->setDefaultDesignTheme();
5564

56-
$actualHtml = $this->_block->getLayoutsChooser();
65+
$actualHtml = $this->block->getLayoutsChooser();
5766
$this->assertStringStartsWith('<select ', $actualHtml);
5867
$this->assertStringEndsWith('</select>', $actualHtml);
5968
$this->assertStringContainsString('id="layout_handle"', $actualHtml);
6069
$optionCount = substr_count($actualHtml, '<option ');
6170
$this->assertGreaterThan(1, $optionCount, 'HTML select tag must provide options to choose from.');
6271
$this->assertEquals($optionCount, substr_count($actualHtml, '</option>'));
6372
}
73+
74+
/**
75+
* Check that escapeUrl called from template
76+
*
77+
* @return void
78+
*/
79+
public function testToHtml(): void
80+
{
81+
$escaperMock = $this->createMock(Escaper::class);
82+
$this->objectManager->addSharedInstance($escaperMock, Escaper::class);
83+
84+
$escaperMock->expects($this->atLeast(6))
85+
->method('escapeUrl');
86+
87+
$this->block->toHtml();
88+
}
89+
90+
/**
91+
* @inheritDoc
92+
*/
93+
protected function tearDown(): void
94+
{
95+
$this->objectManager->removeSharedInstance(Escaper::class);
96+
}
6497
}

0 commit comments

Comments
 (0)