/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Cms/Model/BlockTest.php
130 строк
4 KB
Raj Mohan R
AC-16236::Upgrade Core Test Framework to PHPUnit 12 and Migrate from PHPUnit 10
11 фев 2026, 13:51
11 фев 2026, 13:51
152ed41
Код
Авторство
О чём код?
<?php /** * Copyright 2017 Adobe * All Rights Reserved. */ namespace Magento\Cms\Model; use Magento\Cms\Model\ResourceModel\Block; use Magento\Cms\Model\BlockFactory; use Magento\Framework\App\ResourceConnection; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Stdlib\DateTime\Timezone; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\DataProvider; /** * @magentoAppArea adminhtml */ class BlockTest extends TestCase { /** * @var ObjectManagerInterface */ private $objectManager; /** * @var Block */ private $blockResource; /** * @var BlockFactory */ private $blockFactory; /** * @var GetBlockByIdentifier */ private $blockIdentifier; protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); /** @var BlockFactory $blockFactory */ /** @var Block $blockResource */ /** @var GetBlockByIdentifier $getBlockByIdentifierCommand */ $this->blockResource = $this->objectManager->create(Block::class); $this->blockFactory = $this->objectManager->create(BlockFactory::class); $this->blockIdentifier = $this->objectManager->create(GetBlockByIdentifier::class); } /** * Tests the get by identifier command * @param array $blockData * @throws \Exception * @throws \Magento\Framework\Exception\NoSuchEntityException * @magentoDbIsolation enabled */ #[DataProvider('blockGetByIdentifierDataProvider')] public function testGetByIdentifier(array $blockData) { # Prepare and save the temporary block $tempBlock = $this->blockFactory->create(); $tempBlock->setData($blockData); $this->blockResource->save($tempBlock); # Load previously created block and compare identifiers $storeId = reset($blockData['stores']); $block = $this->blockIdentifier->execute($blockData['identifier'], $storeId); $this->assertEquals($blockData['identifier'], $block->getIdentifier()); } /** * Tests the get by identifier command * @param array $blockData * @throws \Exception * @throws \Magento\Framework\Exception\NoSuchEntityException * @magentoDbIsolation enabled */ #[DataProvider('blockGetByIdentifierDataProvider')] public function testUpdateTime(array $blockData) { /** * @var $db \Magento\Framework\DB\Adapter\AdapterInterface */ $db = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class) ->getConnection(ResourceConnection::DEFAULT_CONNECTION); # Prepare and save the temporary block $tempBlock = $this->blockFactory->create(); $tempBlock->setData($blockData); $beforeTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0]; $this->blockResource->save($tempBlock); $afterTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0]; # Load previously created block and compare identifiers $storeId = reset($blockData['stores']); $block = $this->blockIdentifier->execute($blockData['identifier'], $storeId); $blockTimestamp = strtotime($block->getUpdateTime()); /* * These checks prevent a race condition MAGETWO-87353 */ $this->assertGreaterThanOrEqual($beforeTimestamp, $blockTimestamp); $this->assertLessThanOrEqual($afterTimestamp, $blockTimestamp); } /** * Data provider for "testGetByIdentifier" and "testUpdateTime" method * @return array */ public static function blockGetByIdentifierDataProvider(): array { return [ [ 'blockData' => [ 'title' => 'Test title', 'stores' => [0], 'identifier' => 'test-identifier', 'content' => 'Test content', 'is_active' => 1 ] ] ]; } }