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,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model\ItemProvider;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
class CategoryConfigReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CategoryConfigReader
*/
private $model = null;
protected function setUp(): void
{
$this->model = Bootstrap::getObjectManager()->get(CategoryConfigReader::class);
}
/**
* @magentoConfigFixture default_store sitemap/category/changefreq monthly
*/
public function testGetChangeFrequency()
{
$this->assertEquals('daily', $this->model->getChangeFrequency(Store::DEFAULT_STORE_ID));
$this->assertEquals('monthly', $this->model->getChangeFrequency(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/category/priority 100
*/
public function testGetCategoryPriority()
{
$this->assertEquals(0.5, $this->model->getPriority(Store::DEFAULT_STORE_ID));
$this->assertEquals(100, $this->model->getPriority(Store::DISTRO_STORE_ID));
}
}
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model\ItemProvider;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
class CmsPageConfigReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CategoryConfigReader
*/
private $model = null;
protected function setUp(): void
{
$this->model = Bootstrap::getObjectManager()->get(CmsPageConfigReader::class);
}
/**
* @magentoConfigFixture default_store sitemap/page/changefreq monthly
*/
public function testGetChangeFrequency()
{
$this->assertEquals('daily', $this->model->getChangeFrequency(Store::DEFAULT_STORE_ID));
$this->assertEquals('monthly', $this->model->getChangeFrequency(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/page/priority 100
*/
public function testGetCategoryPriority()
{
$this->assertEquals(0.25, $this->model->getPriority(Store::DEFAULT_STORE_ID));
$this->assertEquals(100, $this->model->getPriority(Store::DISTRO_STORE_ID));
}
}
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model\ItemProvider;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
class ProductConfigReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CategoryConfigReader
*/
private $model = null;
protected function setUp(): void
{
$this->model = Bootstrap::getObjectManager()->get(ProductConfigReader::class);
}
/**
* @magentoConfigFixture default_store sitemap/product/changefreq monthly
*/
public function testGetChangeFrequency()
{
$this->assertEquals('daily', $this->model->getChangeFrequency(Store::DEFAULT_STORE_ID));
$this->assertEquals('monthly', $this->model->getChangeFrequency(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/product/priority 100
*/
public function testGetCategoryPriority()
{
$this->assertEquals(1, $this->model->getPriority(Store::DEFAULT_STORE_ID));
$this->assertEquals(100, $this->model->getPriority(Store::DISTRO_STORE_ID));
}
}
@@ -0,0 +1,194 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model\ResourceModel\Catalog;
/**
* Test class for \Magento\Sitemap\Model\ResourceModel\Catalog\Product.
* - test products collection generation for sitemap
*
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php
* @magentoDataFixture Magento/Sitemap/_files/sitemap_products.php
*/
class ProductTest extends \PHPUnit\Framework\TestCase
{
/**
* Base product image path
*/
const BASE_IMAGE_PATH = '#http://localhost/media/catalog/product/cache/[a-z0-9]{32}:path:#';
/**
* Test getCollection None images
* 1) Check that image attributes were not loaded
* 2) Check no images were loaded
*
* @magentoConfigFixture default_store sitemap/product/image_include none
*/
public function testGetCollectionNone()
{
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
);
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
$this->_checkProductCollection($products, 3, [1, 4, 5]);
// Check that no image attributes were loaded
foreach ($products as $product) {
$this->assertEmpty($product->getName(), 'Attribute name is not empty');
$this->assertEmpty($product->getImage(), 'Attribute image is not empty');
$this->assertEmpty($product->getThumbnail(), 'Attribute thumbnail is not empty');
}
$this->assertEmpty($products[4]->getImages(), 'Images were loaded');
}
/**
* Test getCollection All images
* 1) Check thumbnails
* 2) Check images loading
* 3) Check thumbnails when no thumbnail selected
*
* @magentoConfigFixture default_store sitemap/product/image_include all
* @magentoConfigFixture default/web/url/catalog_media_url_format hash
*/
public function testGetCollectionAll()
{
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
);
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
$this->_checkProductCollection($products, 3, [1, 4, 5]);
// Check name attribute was loaded
foreach ($products as $product) {
$this->assertNotEmpty($product->getName(), 'name attribute was not loaded');
}
// Check thumbnail attribute
$this->assertEmpty($products[1]->getThumbnail(), 'Thumbnail attribute was loaded');
$this->assertEmpty($products[4]->getImage(), 'Image attribute was loaded');
$this->assertEquals('/m/a/magento_image_sitemap.png', $products[4]->getThumbnail(), 'Incorrect thumbnail');
// Check images loading
$this->assertEmpty($products[1]->getImages(), 'Images were loaded');
$this->assertNotEmpty($products[4]->getImages(), 'Images were not loaded');
$this->assertEquals('Simple Images', $products[4]->getImages()->getTitle(), 'Incorrect title');
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/m/a/magento_image_sitemap.png'), self::BASE_IMAGE_PATH),
$products[4]->getImages()->getThumbnail(),
'Incorrect thumbnail'
);
$this->assertCount(2, $products[4]->getImages()->getCollection(), 'Not all images were loaded');
$imagesCollection = $products[4]->getImages()->getCollection();
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/m/a/magento_image_sitemap.png'), self::BASE_IMAGE_PATH),
$imagesCollection[0]->getUrl(),
'Incorrect image url'
);
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/s/e/second_image.png'), self::BASE_IMAGE_PATH),
$imagesCollection[1]->getUrl(),
'Incorrect image url'
);
$this->assertEmpty($imagesCollection[0]->getCaption(), 'Caption not empty');
// Check no selection
$this->assertEmpty($products[5]->getImage(), 'image is not empty');
$this->assertEquals('no_selection', $products[5]->getThumbnail(), 'thumbnail is incorrect');
$imagesCollection = $products[5]->getImages()->getCollection();
$this->assertCount(1, $imagesCollection);
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/s/e/second_image_1.png'), self::BASE_IMAGE_PATH),
$imagesCollection[0]->getUrl(),
'Image url is incorrect'
);
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/s/e/second_image_1.png'), self::BASE_IMAGE_PATH),
$products[5]->getImages()->getThumbnail(),
'Product thumbnail is incorrect'
);
}
/**
* Test getCollection None images
* 1) Check that image attributes were not loaded
* 2) Check no images were loaded
* 3) Check thumbnails when no thumbnail selected
*
* @magentoConfigFixture default_store sitemap/product/image_include base
* @magentoConfigFixture default/web/url/catalog_media_url_format hash
*/
public function testGetCollectionBase()
{
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
);
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
$this->_checkProductCollection($products, 3, [1, 4, 5]);
// Check name attribute was loaded
foreach ($products as $product) {
$this->assertNotEmpty($product->getName(), 'name attribute was not loaded');
}
// Check thumbnail attribute
$this->assertEmpty($products[1]->getImage(), 'image attribute was loaded');
$this->assertEmpty($products[4]->getThumbnail(), 'thumbnail attribute was loaded');
$this->assertEquals('/s/e/second_image.png', $products[4]->getImage(), 'Incorrect image attribute');
// Check images loading
$this->assertEmpty($products[1]->getImages(), 'Images were loaded');
$this->assertNotEmpty($products[4]->getImages(), 'Images were not loaded');
$this->assertEquals('Simple Images', $products[4]->getImages()->getTitle(), 'Incorrect title');
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/s/e/second_image.png'), self::BASE_IMAGE_PATH),
$products[4]->getImages()->getThumbnail(),
'Incorrect thumbnail'
);
$this->assertCount(1, $products[4]->getImages()->getCollection(), 'Number of loaded images is incorrect');
$imagesCollection = $products[4]->getImages()->getCollection();
$this->assertMatchesRegularExpression(
str_replace(':path:', preg_quote('/s/e/second_image.png'), self::BASE_IMAGE_PATH),
$imagesCollection[0]->getUrl(),
'Incorrect image url'
);
$this->assertEmpty($imagesCollection[0]->getCaption(), 'Caption not empty');
// Check no selection
$this->assertEmpty($products[5]->getThumbnail(), 'thumbnail is not empty');
$this->assertEquals('no_selection', $products[5]->getImage(), 'image is incorrect');
$this->assertEmpty($products[5]->getImages(), 'Product images were loaded');
}
/**
* Check product collection
* 1) Check that all products are loaded
* 2) Check that products are loaded correctly and all required attributes present
*
* @param array $products
* @param int $expectedCount
* @param array $expectedKeys
*/
protected function _checkProductCollection(array $products, $expectedCount, array $expectedKeys)
{
// Check all expected products were added into collection
$this->assertCount($expectedCount, $products, 'Number of loaded products is incorrect');
foreach ($expectedKeys as $expectedKey) {
$this->assertArrayHasKey($expectedKey, $products);
}
// Check all expected attributes are present
foreach ($products as $product) {
$this->assertNotEmpty($product->getUpdatedAt());
$this->assertNotEmpty($product->getId());
$this->assertNotEmpty($product->getUrl());
}
}
}
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model\ResourceModel\Cms;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Provide tests for Cms Page resource model.
*/
class PageTest extends TestCase
{
/**
* Test subject.
*
* @var Page
*/
private $page;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->page = Bootstrap::getObjectManager()->get(Page::class);
}
/**
* Test Page::getCollection() will exclude home and no-route cms pages for site map.
*
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Cms/_files/pages.php
* @return void
*/
public function testGetCollection()
{
$excludedUrls = ['no-route', 'home'];
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
$result = $this->page->getCollection($storeManager->getDefaultStoreView()->getId());
$this->assertNotEmpty($result);
foreach ($result as $item) {
$this->assertFalse(in_array($item->getUrl(), $excludedUrls));
}
}
}
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sitemap\Model;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
class SitemapConfigReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var SitemapConfigReader
*/
private $model = null;
protected function setUp(): void
{
$this->model = Bootstrap::getObjectManager()->get(SitemapConfigReader::class);
}
/**
* @magentoConfigFixture default_store sitemap/search_engines/submission_robots 1
*/
public function testGetEnableSubmissionRobots()
{
$this->assertEquals(0, $this->model->getEnableSubmissionRobots(Store::DEFAULT_STORE_ID));
$this->assertEquals(1, $this->model->getEnableSubmissionRobots(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/limit/max_lines 10
*/
public function testGetMaximumLinesNumber()
{
$this->assertEquals(50000, $this->model->getMaximumLinesNumber(Store::DEFAULT_STORE_ID));
$this->assertEquals(10, $this->model->getMaximumLinesNumber(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/limit/max_file_size 1024
*/
public function testGetMaximumFileSize()
{
$this->assertEquals(10485760, $this->model->getMaximumFileSize(Store::DEFAULT_STORE_ID));
$this->assertEquals(1024, $this->model->getMaximumFileSize(Store::DISTRO_STORE_ID));
}
/**
* @magentoConfigFixture default_store sitemap/product/image_include base
*/
public function testGetProductImageIncludePolicy()
{
$this->assertEquals('all', $this->model->getProductImageIncludePolicy(Store::DEFAULT_STORE_ID));
$this->assertEquals('base', $this->model->getProductImageIncludePolicy(Store::DISTRO_STORE_ID));
}
}
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Sitemap\Model;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\ObjectManagerInterface;
use Magento\Sitemap\Model\Sitemap;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Request;
use Laminas\Stdlib\Parameters;
use PHPUnit\Framework\TestCase;
/**
* Tests \Magento\Sitemap\Model\Sitemap functionality.
*/
class SitemapTest extends TestCase
{
/**
* @var Sitemap
*/
private $model;
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var Filesystem
*/
private $filesystem;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->model = $this->objectManager->get(Sitemap::class);
$this->filesystem = $this->objectManager->get(Filesystem::class);
}
/**
* Test get sitemap URL from parent root directory path
*
* @return void
*/
public function testGetSitemapUrlFromParentRootDirectoryPath(): void
{
$rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)
->getAbsolutePath();
$requestPath = dirname($rootDir);
/** @var Request $request */
$request = $this->objectManager->get(Request::class);
//imitation run script from parent root directory
$request->setServer(new Parameters(['DOCUMENT_ROOT' => $requestPath]));
$sitemapUrl = $this->model->getSitemapUrl('/', 'sitemap.xml');
$this->assertEquals('http://localhost/sitemap.xml', $sitemapUrl);
}
}