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,80 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Indexer\Console\Command;
use Magento\Framework\Console\Cli;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\MockObject\MockObject as Mock;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Tests for \Magento\Indexer\Console\Command\IndexerReindexCommand.
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
class IndexerReindexCommandTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var InputInterface|Mock
*/
private $inputMock;
/**
* @var OutputInterface|Mock
*/
private $outputMock;
/**
* @var IndexerReindexCommand
*/
private $command;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->inputMock = $this->getMockBuilder(InputInterface::class)->getMockForAbstractClass();
$this->outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
$this->command = $this->objectManager->get(IndexerReindexCommand::class);
}
/**
* @magentoDataFixture Magento/Store/_files/second_store_group_with_second_website.php
* @return void
*/
public function testReindexAll(): void
{
$status = $this->command->run($this->inputMock, $this->outputMock);
$this->assertEquals(Cli::RETURN_SUCCESS, $status, 'Index wasn\'t success');
}
/**
* Check that 'indexer:reindex' command return right code.
*
* @magentoDataFixture Magento/Indexer/_files/wrong_config_data.php
* @return void
*/
public function testReindexAllWhenSomethingIsWrong(): void
{
$status = $this->command->run($this->inputMock, $this->outputMock);
$this->assertEquals(Cli::RETURN_FAILURE, $status, 'Index didn\'t return failure code');
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Controller\Adminhtml;
/**
* @magentoAppArea adminhtml
*/
class IndexerTest extends \Magento\TestFramework\TestCase\AbstractBackendController
{
/**
* Assert that current page is index management page and that it has indexers mode selector
*
* @return void
*/
public function testIndexersMode()
{
$this->dispatch('backend/indexer/indexer/list/');
$body = $this->getResponse()->getBody();
$this->assertStringContainsString('<h1 class="page-title">Index Management</h1>', $body);
$this->assertEquals(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[@id="gridIndexer_massaction-select"]',
$body
),
'Mode selector is not found'
);
$this->assertStringContainsString('option value="change_mode_onthefly"', $body);
$this->assertStringContainsString('option value="change_mode_changelog"', $body);
}
/**
* Assert that index management contains a certain number of indexers
*
* @return void
*/
public function testDefaultNumberOfIndexers()
{
$this->dispatch('backend/indexer/indexer/list/');
$body = $this->getResponse()->getBody();
$this->assertGreaterThanOrEqual(
1,
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
'//*[@name="indexer_ids"]',
$body
),
'Indexer list is empty'
);
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Model\Config;
use Magento\Framework\Exception\ConfigurationMismatchException;
class ConverterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\Indexer\Config\Converter
*/
protected $model;
protected function setUp(): void
{
$this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Framework\Indexer\Config\Converter::class);
}
public function testConverter()
{
$pathFiles = __DIR__ . '/_files';
$expectedResult = require $pathFiles . '/result.php';
$path = $pathFiles . '/indexer.xml';
$domDocument = new \DOMDocument();
$domDocument->load($path);
$result = $this->model->convert($domDocument);
$this->assertEquals($expectedResult, $result);
}
/**
* @return void
*/
public function testConverterWithCircularDependency()
{
$pathFiles = __DIR__ . '/_files';
$path = $pathFiles . '/indexer_with_circular_dependency.xml';
$domDocument = new \DOMDocument();
$domDocument->load($path);
$this->expectException(ConfigurationMismatchException::class);
$this->expectExceptionMessage('Circular dependency references from');
$this->model->convert($domDocument);
}
/**
* @return void
*/
public function testConverterWithDependencyOnNotExistingIndexer()
{
$pathFiles = __DIR__ . '/_files';
$path = $pathFiles . '/dependency_on_not_existing_indexer.xml';
$domDocument = new \DOMDocument();
$domDocument->load($path);
$this->expectException(ConfigurationMismatchException::class);
$this->expectExceptionMessage("Dependency declaration 'indexer_4' in 'indexer_2' to the non-existing indexer.");
$this->model->convert($domDocument);
}
}
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="indexer_2" view_id="indexer_2"
class="Magento\Module\IndexerSecond">
<dependencies>
<indexer id="indexer_4" />
</dependencies>
</indexer>
<indexer id="indexer_3" view_id="indexer_3"
class="Magento\Module\IndexerThird">
</indexer>
</config>
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="catalogsearch_fulltext" view_id="catalogsearch_fulltext"
class="Magento\CatalogSearch\Model\Indexer\Fulltext"
primary="first">
<title translate="true">Catalog Search</title>
<description translate="true">Rebuild Catalog product fulltext search index</description>
<fieldset name="first" source="MagentoModule\ServiceClassOrRepositoryClass"
provider="Magento\Indexer\Model\Fieldset\ProductFieldset">
<field name="title_alias" origin="title" xsi:type="searchable" dataType="text">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
<field name="identifier" xsi:type="filterable" handler="Magento\Framework\Search\Index\Handler"/>
</fieldset>
<fieldset name="second" source="MagentoModule\ServiceClassOrRepositoryClass">
<reference fieldset="first" from="id_field" to="second_entity_id"/>
<field name="title" xsi:type="searchable"/>
</fieldset>
<saveHandler class="Magento\Cms\Model\Indexer\StoreResource"/>
<structure class="Magento\Cms\Model\Indexer\IndexStructure"/>
<dependencies>
<indexer id="indexer_2"/>
</dependencies>
</indexer>
<indexer id="indexer_2" view_id="indexer_2"
class="Magento\Module\IndexerSecond">
<dependencies>
<indexer id="indexer_4" />
</dependencies>
</indexer>
<indexer id="indexer_3" view_id="indexer_3"
class="Magento\Module\IndexerThird">
</indexer>
<indexer id="indexer_4" view_id="indexer_4"
class="Magento\Module\IndexerFourth">
</indexer>
</config>
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="catalogsearch_fulltext" view_id="catalogsearch_fulltext"
class="Magento\CatalogSearch\Model\Indexer\Fulltext"
primary="first">
<title translate="true">Catalog Search</title>
<description translate="true">Rebuild Catalog product fulltext search index</description>
<fieldset name="first" source="MagentoModule\ServiceClassOrRepositoryClass"
provider="Magento\Indexer\Model\Fieldset\ProductFieldset">
<field name="title_alias" origin="title" xsi:type="searchable" dataType="text">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
<field name="identifier" xsi:type="filterable" handler="Magento\Framework\Search\Index\Handler"/>
</fieldset>
<fieldset name="second" source="MagentoModule\ServiceClassOrRepositoryClass">
<reference fieldset="first" from="id_field" to="second_entity_id"/>
<field name="title" xsi:type="searchable"/>
</fieldset>
<saveHandler class="Magento\Cms\Model\Indexer\StoreResource"/>
<structure class="Magento\Cms\Model\Indexer\IndexStructure"/>
<dependencies>
<indexer id="indexer_2"/>
</dependencies>
</indexer>
<indexer id="indexer_2" view_id="indexer_2"
class="Magento\Module\IndexerSecond">
<dependencies>
<indexer id="indexer_4" />
</dependencies>
</indexer>
<indexer id="indexer_3" view_id="indexer_3"
class="Magento\Module\IndexerThird">
</indexer>
<indexer id="indexer_4" view_id="indexer_4"
class="Magento\Module\IndexerFourth">
<dependencies>
<indexer id="catalogsearch_fulltext" />
</dependencies>
</indexer>
</config>
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'indexer_4' => [
'indexer_id' => 'indexer_4',
'view_id' => 'indexer_4',
'primary' => null,
'action_class' => 'Magento\Module\IndexerFourth',
'shared_index' => null,
'title' => '',
'description' => '',
'dependencies' => [],
],
'indexer_2' => [
'indexer_id' => 'indexer_2',
'view_id' => 'indexer_2',
'primary' => null,
'action_class' => 'Magento\Module\IndexerSecond',
'shared_index' => null,
'title' => '',
'description' => '',
'fieldsets' => [],
'dependencies' => [
'indexer_4'
],
],
'catalogsearch_fulltext' => [
'indexer_id' => 'catalogsearch_fulltext',
'shared_index' => null,
'primary' => 'first',
'view_id' => 'catalogsearch_fulltext',
'action_class' => \Magento\CatalogSearch\Model\Indexer\Fulltext::class,
'title' => __('Catalog Search'),
'description' => __('Rebuild Catalog product fulltext search index'),
'fieldsets' => [
[
'source' => 'MagentoModule\\ServiceClassOrRepositoryClass',
'name' => 'first',
'provider' => \Magento\Indexer\Model\Fieldset\ProductFieldset::class,
'fields' => [
'title_alias' => [
'name' => 'title_alias',
'handler' => null,
'origin' => 'title',
'dataType' => 'text',
'type' => 'searchable',
'filters' =>
[
0 => \Magento\Framework\Search\Index\Filter\LowercaseFilter::class,
],
],
'identifier' => [
'name' => 'identifier',
'handler' => \Magento\Framework\Search\Index\Handler::class,
'origin' => 'identifier',
'dataType' => null,
'type' => 'filterable',
'filters' =>
[],
],
],
],
[
'source' => 'MagentoModule\\ServiceClassOrRepositoryClass',
'name' => 'second',
'provider' => null,
'fields' => [
'title' =>
[
'name' => 'title',
'handler' => null,
'origin' => 'title',
'dataType' => null,
'type' => 'searchable',
'filters' =>
[],
],
],
'references' => [
'first' =>
[
'fieldset' => 'first',
'from' => 'id_field',
'to' => 'second_entity_id',
]
],
],
],
'saveHandler' => \Magento\Cms\Model\Indexer\StoreResource::class,
'structure' => \Magento\Cms\Model\Indexer\IndexStructure::class,
'dependencies' => ['indexer_2'],
],
'indexer_3' => [
'indexer_id' => 'indexer_3',
'view_id' => 'indexer_3',
'primary' => null,
'action_class' => 'Magento\Module\IndexerThird',
'shared_index' => null,
'title' => '',
'description' => '',
'dependencies' => [],
],
];
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Indexer\Model\Indexer;
use Magento\Framework\Indexer\CacheContext;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Test deferring cache clean up
*/
class DeferCacheCleaningTest extends TestCase
{
/**
* Test that cache tags registrations are deferred if cache context is deferred
*/
public function testDeferredCacheCleaning(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var DeferredCacheContext $deferredCacheContext */
$deferredCacheContext = $objectManager->get(DeferredCacheContext::class);
/** @var CacheContext $cacheContext */
$cacheContext = $objectManager->get(CacheContext::class);
$cacheContext->flush();
$deferredCacheContext->start();
$cacheContext->registerTags(['test_tag_1', 'test_tag_2']);
$cacheContext->registerEntities('test_tag_ent_1', [1, 2, 3]);
$deferredCacheContext->start();
$cacheContext->registerEntities('test_tag_ent_2', [7, 8, 9]);
$cacheContext->registerTags(['test_tag_1', 'test_tag_3']);
$this->assertEmpty($cacheContext->getIdentities());
$deferredCacheContext->commit();
$this->assertEmpty($cacheContext->getIdentities());
$deferredCacheContext->commit();
$this->assertEquals(
[
'test_tag_ent_1_1',
'test_tag_ent_1_2',
'test_tag_ent_1_3',
'test_tag_ent_2_7',
'test_tag_ent_2_8',
'test_tag_ent_2_9',
'test_tag_1',
'test_tag_2',
'test_tag_3'
],
$cacheContext->getIdentities()
);
$cacheContext->flush();
}
}
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Indexer\Model\Processor;
use Magento\TestFramework\Helper\Bootstrap;
/** @var Processor $processor */
$processor = Bootstrap::getObjectManager()->get(Processor::class);
$processor->reindexAllInvalid();
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Config\Model\Config\Factory;
use Magento\TestFramework\Helper\Bootstrap;
/** @var Factory $configFactory */
$configFactory = Bootstrap::getObjectManager()->get(Factory::class);
$config = $configFactory->create();
$config->setScope('stores');
$engine = $config->getConfigDataValue('catalog/search/engine');
$portField = "catalog/search/{$engine}_server_port";
$config->setDataByPath($portField, 2309);
$config->save();
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Config\Model\Config\Factory;
use Magento\Framework\App\ResourceConnection;
use Magento\TestFramework\Helper\Bootstrap;
/** @var ResourceConnection $resource */
$resource = Bootstrap::getObjectManager()->get(ResourceConnection::class);
$connection = $resource->getConnection();
$tableName = $resource->getTableName('core_config_data');
$configFactory = Bootstrap::getObjectManager()->get(Factory::class);
$config = $configFactory->create();
$config->setScope('stores');
$engine = $config->getConfigDataValue('catalog/search/engine');
$portField = "catalog/search/{$engine}_server_port";
$connection->query("DELETE FROM $tableName WHERE path = '{$portField}'"
." AND scope = 'stores';");