init
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sitemap\Block;
|
||||
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Sitemap\Model\SitemapFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Sitemap\Block\Robots.
|
||||
*/
|
||||
class RobotsTest extends TestCase
|
||||
{
|
||||
private const STUB_SITEMAP_FILENAME = 'sitemap_file.xml';
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var SitemapFactory
|
||||
*/
|
||||
private $sitemapFactory;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @inheridoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$this->sitemapFactory = Bootstrap::getObjectManager()->get(SitemapFactory::class);
|
||||
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test toHtml with few websites
|
||||
*
|
||||
* @magentoDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
|
||||
* @magentoConfigFixture default_store sitemap/search_engines/submission_robots 1
|
||||
* @magentoConfigFixture second_store_view_store sitemap/search_engines/submission_robots 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToHtml(): void
|
||||
{
|
||||
$secondSitemapFile = 'second_' . self::STUB_SITEMAP_FILENAME;
|
||||
|
||||
$this->createSitemap(self::STUB_SITEMAP_FILENAME, 1);
|
||||
$this->createSitemap($secondSitemapFile, 2);
|
||||
|
||||
$this->assertStringContainsString(self::STUB_SITEMAP_FILENAME, $this->getToHtmlOutput(1));
|
||||
$this->assertStringContainsString($secondSitemapFile, $this->getToHtmlOutput(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns toHtml output per store
|
||||
*
|
||||
* @param int $storeId
|
||||
* @return string
|
||||
*/
|
||||
private function getToHtmlOutput(int $storeId): string
|
||||
{
|
||||
$this->storeManager->setCurrentStore($storeId);
|
||||
$block = $this->layout->createBlock(Robots::class);
|
||||
|
||||
return $block->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Sitemap
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param int $storeId
|
||||
* @param string $siteMath
|
||||
* @return void
|
||||
*/
|
||||
private function createSitemap(string $fileName, int $storeId, string $siteMath = '/'): void
|
||||
{
|
||||
$model = $this->sitemapFactory->create();
|
||||
$model->setData(['sitemap_filename' => $fileName, 'store_id' => $storeId, 'sitemap_path' => $siteMath]);
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
+41
@@ -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));
|
||||
}
|
||||
}
|
||||
+41
@@ -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));
|
||||
}
|
||||
}
|
||||
+41
@@ -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));
|
||||
}
|
||||
}
|
||||
+194
@@ -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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// Copy images to tmp media path
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Model\Product\Media\Config $config */
|
||||
$config = $objectManager->get(\Magento\Catalog\Model\Product\Media\Config::class);
|
||||
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
|
||||
$mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
$baseTmpMediaPath = $config->getBaseTmpMediaPath();
|
||||
$mediaDirectory->create($baseTmpMediaPath);
|
||||
|
||||
$imageSitemapPath = $mediaDirectory->getAbsolutePath($baseTmpMediaPath . '/magento_image_sitemap.png');
|
||||
$secondImagePath = $mediaDirectory->getAbsolutePath($baseTmpMediaPath . '/second_image.png');
|
||||
|
||||
$imageSitemapContent = file_get_contents(__DIR__ . '/magento_image_sitemap.png');
|
||||
$secondImageContent = file_get_contents(__DIR__ . '/second_image.png');
|
||||
$mediaDirectory->getDriver()->filePutContents($imageSitemapPath, $imageSitemapContent);
|
||||
$mediaDirectory->getDriver()->filePutContents($secondImagePath, $secondImageContent);
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
1
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Product Enabled'
|
||||
)->setSku(
|
||||
'simple_no_images'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $objectManager->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
|
||||
$productLink->setSku('simple_invisible');
|
||||
$productLink->setLinkedProductSku('simple_no_images');
|
||||
$productLink->setPosition(1);
|
||||
$productLink->setLinkType('related');
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
2
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Product Invisible'
|
||||
)->setSku(
|
||||
'simple_invisible'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1]
|
||||
)->setRelatedLinkData(
|
||||
[$productLink]
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $objectManager->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
|
||||
$productLink->setSku('simple_disabled');
|
||||
$productLink->setLinkedProductSku('simple_no_images');
|
||||
$productLink->setPosition(1);
|
||||
$productLink->setLinkType('related');
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
3
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Product Disabled'
|
||||
)->setSku(
|
||||
'simple_disabled'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1]
|
||||
)->setRelatedLinkData(
|
||||
[$productLink]
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $objectManager->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
|
||||
$productLink->setSku('simple_with_images');
|
||||
$productLink->setLinkedProductSku('simple_no_images');
|
||||
$productLink->setPosition(1);
|
||||
$productLink->setLinkType('related');
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
4
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Images'
|
||||
)->setSku(
|
||||
'simple_with_images'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setImage(
|
||||
'/s/e/second_image.png'
|
||||
)->setSmallImage(
|
||||
'/m/a/magento_image_sitemap.png'
|
||||
)->setThumbnail(
|
||||
'/m/a/magento_image_sitemap.png'
|
||||
)->addImageToMediaGallery(
|
||||
$imageSitemapPath,
|
||||
null,
|
||||
false,
|
||||
false
|
||||
)->addImageToMediaGallery(
|
||||
$secondImagePath,
|
||||
null,
|
||||
false,
|
||||
false
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1]
|
||||
)->setRelatedLinkData(
|
||||
[$productLink]
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $objectManager->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
|
||||
$productLink->setSku('simple_with_images');
|
||||
$productLink->setLinkedProductSku('simple_no_images');
|
||||
$productLink->setPosition(1);
|
||||
$productLink->setLinkType('related');
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
5
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Images Two'
|
||||
)->setSku(
|
||||
'simple_with_images'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setImage(
|
||||
'no_selection'
|
||||
)->setSmallImage(
|
||||
'/m/a/magento_image_sitemap.png'
|
||||
)->setThumbnail(
|
||||
'no_selection'
|
||||
)->addImageToMediaGallery(
|
||||
$baseTmpMediaPath . '/second_image.png',
|
||||
null,
|
||||
false,
|
||||
false
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1]
|
||||
)->setRelatedLinkData(
|
||||
[$productLink]
|
||||
)->save();
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_image_rollback.php');
|
||||
Reference in New Issue
Block a user