This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Block\Html;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppArea frontend
*/
class BreadcrumbsTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Theme\Block\Html\Breadcrumbs
*/
private $block;
/**
* @var SerializerInterface
*/
private $serializer;
protected function setUp(): void
{
Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
$this->block = Bootstrap::getObjectManager()
->get(\Magento\Framework\View\LayoutInterface::class)
->createBlock(\Magento\Theme\Block\Html\Breadcrumbs::class);
$this->serializer = Bootstrap::getObjectManager()->get(SerializerInterface::class);
}
public function testAddCrumb()
{
$this->assertEmpty($this->block->toHtml());
$info = ['label' => 'test label', 'title' => 'test title', 'link' => 'test link'];
$this->block->addCrumb('test', $info);
$html = $this->block->toHtml();
$this->assertStringContainsString('test label', $html);
$this->assertStringContainsString('test title', $html);
$this->assertStringContainsString('test link', $html);
}
public function testGetCacheKeyInfo()
{
$crumbs = ['test' => ['label' => 'test label', 'title' => 'test title', 'link' => 'test link']];
foreach ($crumbs as $crumbName => &$crumb) {
$this->block->addCrumb($crumbName, $crumb);
$crumb += ['first' => null, 'last' => null, 'readonly' => null];
}
$cacheKeyInfo = $this->block->getCacheKeyInfo();
$crumbsFromCacheKey = $this->serializer->unserialize(base64_decode($cacheKeyInfo['crumbs']));
$this->assertEquals($crumbs, $crumbsFromCacheKey);
}
}
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Block\Html;
use Magento\Customer\Model\Context;
class FooterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Theme\Model\Theme
*/
protected $_theme;
protected function setUp(): void
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
->setAreaCode('frontend');
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\DesignInterface::class
);
$this->_theme = $design->setDefaultDesignTheme()->getDesignTheme();
}
public function testGetCacheKeyInfo()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$context = $objectManager->get(\Magento\Framework\App\Http\Context::class);
$context->setValue(Context::CONTEXT_AUTH, false, false);
$block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class)
->createBlock(\Magento\Theme\Block\Html\Footer::class)
->setTemplate('html/copyright.phtml');
$storeId = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId();
$expected = [
'PAGE_FOOTER',
$storeId,
0,
$this->_theme->getId(),
false,
$block->getTemplateFile(),
'template' => 'html/copyright.phtml'
];
$this->assertEquals(
$expected,
$block->getCacheKeyInfo()
);
}
}
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Theme\Block\Html\Header;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolver;
use PHPUnit\Framework\TestCase;
/**
* Test logo page header block
*/
class LogoTest extends TestCase
{
/**
* @var Logo
*/
private $block;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$objectManager = Bootstrap::getObjectManager();
$logoSizeResolver = $objectManager->get(LogoSizeResolver::class);
$this->block = $objectManager->create(LayoutInterface::class)
->createBlock(
Logo::class,
'logo',
[
'data' => [
'logo_size_resolver' => $logoSizeResolver
]
]
);
}
/**
* @magentoAppArea frontend
* @magentoConfigFixture current_store design/header/logo_width 260
* @magentoConfigFixture current_store design/header/logo_height 240
*/
public function testStoreLogoSize()
{
$xpath = '//a[@class="logo"]/img';
$elements = Xpath::getElementsForXpath($xpath, $this->block->toHtml());
$this->assertGreaterThan(0, $elements->count(), 'Cannot find element \'' . $xpath . '"\' in the HTML');
$this->assertEquals(260, $elements->item(0)->getAttribute('width'));
$this->assertEquals(240, $elements->item(0)->getAttribute('height'));
}
}