Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration testing changes for Aligent\Sitemap\Model\ItemProvider\PwaUrl class #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Model/Config/ConfigReaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Aligent Consulting
* Copyright (c) Aligent Consulting (https://www.aligent.com.au)
*/

declare(strict_types=1);

namespace Aligent\Sitemap\Model\Config;

interface ConfigReaderInterface
{
public const CONFIG_XML_PATH_SITEMAP_ENABLED = 'aligent_sitemap/general/enabled';
public const CONFIG_XML_PATH_SITEMAP_EXCLUDE_CMS_PAGE = 'aligent_sitemap/general/exclude_cms_page';
public const CONFIG_XML_PATH_SITEMAP_EXCLUDE_CATEGORY = 'aligent_sitemap/general/exclude_category';
public const CONFIG_XML_PATH_SITEMAP_EXCLUDE_PRODUCT = 'aligent_sitemap/general/exclude_product';
public const CONFIG_XML_PATH_SITEMAP_EXCLUDE_PRODUCT_IMAGES = 'aligent_sitemap/general/exclude_product_images';
public const CONFIG_XML_PATH_SITEMAP_INCLUDE_PWA_PAGES = 'aligent_sitemap/general/include_pwa_pages';
public const CONFIG_XML_PATH_SITEMAP_BASE_URL = 'aligent_sitemap/general/sitemap_base_url';
public const CONFIG_XML_PATH_SITEMAP_PWA_PAGES_URL_KEY = 'aligent_sitemap/general/pwa_pages_url_key';

/**
* Sitemap customization for the default sitemap enabled check
*
* @param int|null $storeId
* @return bool
*/
public function isSitemapCustomizationEnabled(?int $storeId): bool;

/**
* Enabled CMS Page Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
*/
public function isCmsPageExcludeEnabled(?int $storeId): bool;

/**
* Enabled Category Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
*/
public function isCategoryExcludeEnabled(?int $storeId): bool;

/**
* Enabled Product Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
*/
public function isProductExcludeEnabled(?int $storeId): bool;

/**
* Enabled Product Images Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
*/
public function isProductImagesExcludeEnabled(?int $storeId): bool;

/**
* Include PWA Pages to Sitemap Xml check
*
* @param int|null $storeId
* @return bool
*/
public function isPwaPagesInclude(?int $storeId): bool;

/**
* Get Sitemap Base Url
*
* @param int|null $storeId
* @return string
*/
public function getSitemapBaseUrl(?int $storeId): string;

/**
* Get PWA Pages Url Key
*
* @param int|null $storeId
* @return array
*/
public function getPwaPagesUrlKey(?int $storeId): array;
}
51 changes: 9 additions & 42 deletions Model/Config/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\Serialize\Serializer\Json;

class Data
class Data implements ConfigReaderInterface
{
private const CONFIG_XML_PATH_SITEMAP_ENABLED = 'aligent_sitemap/general/enabled';
private const CONFIG_XML_PATH_SITEMAP_EXCLUDE_CMS_PAGE = 'aligent_sitemap/general/exclude_cms_page';
private const CONFIG_XML_PATH_SITEMAP_EXCLUDE_CATEGORY = 'aligent_sitemap/general/exclude_category';
private const CONFIG_XML_PATH_SITEMAP_EXCLUDE_PRODUCT = 'aligent_sitemap/general/exclude_product';
private const CONFIG_XML_PATH_SITEMAP_EXCLUDE_PRODUCT_IMAGES = 'aligent_sitemap/general/exclude_product_images';
private const CONFIG_XML_PATH_SITEMAP_INCLUDE_PWA_PAGES = 'aligent_sitemap/general/include_pwa_pages';
private const CONFIG_XML_PATH_SITEMAP_BASE_URL = 'aligent_sitemap/general/sitemap_base_url';
private const CONFIG_XML_PATH_SITEMAP_PWA_PAGES_URL_KEY = 'aligent_sitemap/general/pwa_pages_url_key';

/**
* @param ScopeConfigInterface $scopeConfig
* @param Json $serializer
Expand All @@ -34,10 +25,7 @@ public function __construct(
}

/**
* Sitemap customization for the default sitemap enabled check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isSitemapCustomizationEnabled(?int $storeId): bool
{
Expand All @@ -49,10 +37,7 @@ public function isSitemapCustomizationEnabled(?int $storeId): bool
}

/**
* Enabled CMS Page Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isCmsPageExcludeEnabled(?int $storeId): bool
{
Expand All @@ -67,10 +52,7 @@ public function isCmsPageExcludeEnabled(?int $storeId): bool
}

/**
* Enabled Category Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isCategoryExcludeEnabled(?int $storeId): bool
{
Expand All @@ -85,10 +67,7 @@ public function isCategoryExcludeEnabled(?int $storeId): bool
}

/**
* Enabled Product Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isProductExcludeEnabled(?int $storeId): bool
{
Expand All @@ -103,10 +82,7 @@ public function isProductExcludeEnabled(?int $storeId): bool
}

/**
* Enabled Product Images Exclude from Sitemap Xml check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isProductImagesExcludeEnabled(?int $storeId): bool
{
Expand All @@ -121,10 +97,7 @@ public function isProductImagesExcludeEnabled(?int $storeId): bool
}

/**
* Include PWA Pages to Sitemap Xml check
*
* @param int|null $storeId
* @return bool
* @inheritDoc
*/
public function isPwaPagesInclude(?int $storeId): bool
{
Expand All @@ -139,10 +112,7 @@ public function isPwaPagesInclude(?int $storeId): bool
}

/**
* Get Sitemap Base Url
*
* @param int|null $storeId
* @return string
* @inheritDoc
*/
public function getSitemapBaseUrl(?int $storeId): string
{
Expand All @@ -157,10 +127,7 @@ public function getSitemapBaseUrl(?int $storeId): string
}

/**
* Get PWA Pages Url Key
*
* @param int|null $storeId
* @return array
* @inheritDoc
*/
public function getPwaPagesUrlKey(?int $storeId): array
{
Expand Down
10 changes: 5 additions & 5 deletions Model/ItemProvider/PwaUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Magento\Sitemap\Model\SitemapItemInterfaceFactory;
use Magento\Sitemap\Model\ItemProvider\ItemProviderInterface;
use Magento\Sitemap\Model\ItemProvider\ConfigReaderInterface;
use Aligent\Sitemap\Model\Config\Data as AligentSitemapConfig;
use Aligent\Sitemap\Model\Config\ConfigReaderInterface as AligentSitemapConfigReaderInterface;

class PwaUrl implements ItemProviderInterface
{
Expand All @@ -20,12 +20,12 @@ class PwaUrl implements ItemProviderInterface
*
* @param ConfigReaderInterface $configReader
* @param SitemapItemInterfaceFactory $itemFactory
* @param AligentSitemapConfig $aligentSitemapConfig
* @param AligentSitemapConfigReaderInterface $aligentSitemapConfigReaderInterface
*/
public function __construct(
private readonly ConfigReaderInterface $configReader,
private readonly SitemapItemInterfaceFactory $itemFactory,
private readonly AligentSitemapConfig $aligentSitemapConfig
private readonly AligentSitemapConfigReaderInterface $aligentSitemapConfigReaderInterface
) {
}

Expand All @@ -35,8 +35,8 @@ public function __construct(
public function getItems($storeId): array
{
$items = [];
if ($this->aligentSitemapConfig->isPwaPagesInclude((int)$storeId)) {
$pwaPagesUrlKeys = $this->aligentSitemapConfig->getPwaPagesUrlKey((int)$storeId);
if ($this->aligentSitemapConfigReaderInterface->isPwaPagesInclude((int)$storeId)) {
$pwaPagesUrlKeys = $this->aligentSitemapConfigReaderInterface->getPwaPagesUrlKey((int)$storeId);
foreach ($pwaPagesUrlKeys as $pwaPagesUrlKey) {
$items[] = $this->itemFactory->create([
'url' => $pwaPagesUrlKey,
Expand Down
6 changes: 3 additions & 3 deletions Model/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Magento\Sitemap\Model\SitemapItemInterfaceFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Sitemap\Helper\Data as SitemapHelper;
use Aligent\Sitemap\Model\Config\Data as AligentSitemapConfig;
use Aligent\Sitemap\Model\Config\ConfigReaderInterface as AligentSitemapConfigReaderInterface;

class Sitemap extends MagentoSitemap
{
Expand All @@ -46,7 +46,7 @@ class Sitemap extends MagentoSitemap
* @param StoreManagerInterface $storeManager
* @param RequestInterface $request
* @param DateTime $dateTime
* @param AligentSitemapConfig $aligentSitemapConfig
* @param AligentSitemapConfigReaderInterface $aligentSitemapConfig
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
Expand All @@ -68,7 +68,7 @@ public function __construct(
StoreManagerInterface $storeManager,
RequestInterface $request,
DateTime $dateTime,
private readonly AligentSitemapConfig $aligentSitemapConfig,
private readonly AligentSitemapConfigReaderInterface $aligentSitemapConfig,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
use Aligent\Sitemap\Model\Config\Data as AligentSitemapConfig;
use Aligent\Sitemap\Model\Config\ConfigReaderInterface as AligentSitemapConfigReaderInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\DataObject;

Expand All @@ -31,13 +31,13 @@ class GetValidCategoryPagesForSitemap
private $_attributesCache = [];

/**
* @param AligentSitemapConfig $aligentSitemapConfig
* @param AligentSitemapConfigReaderInterface $aligentSitemapConfig
* @param StoreManagerInterface $storeManager
* @param CategoryResource $categoryResource
* @param MetadataPool $metadataPool
*/
public function __construct(
private readonly AligentSitemapConfig $aligentSitemapConfig,
private readonly AligentSitemapConfigReaderInterface $aligentSitemapConfig,
private readonly StoreManagerInterface $storeManager,
private readonly CategoryResource $categoryResource,
private readonly MetadataPool $metadataPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Zend_Db_Statement_Exception;
use Aligent\Sitemap\Model\Config\Data as AligentSitemapConfig;
use Aligent\Sitemap\Model\Config\ConfigReaderInterface as AligentSitemapConfigReaderInterface;
use Magento\Sitemap\Model\ResourceModel\Catalog\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
Expand All @@ -35,7 +35,7 @@ class GetValidProductPagesForSitemap
/**
* Product constructor.
*
* @param AligentSitemapConfig $aligentSitemapConfig
* @param AligentSitemapConfigReaderInterface $aligentSitemapConfig
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param ProductResource $productResource
Expand All @@ -47,7 +47,7 @@ class GetValidProductPagesForSitemap
* @param ReadHandler $mediaGalleryReadHandler
*/
public function __construct(
private readonly AligentSitemapConfig $aligentSitemapConfig,
private readonly AligentSitemapConfigReaderInterface $aligentSitemapConfig,
private readonly ScopeConfigInterface $scopeConfig,
private readonly StoreManagerInterface $storeManager,
private readonly ProductResource $productResource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Magento\Cms\Api\GetUtilityPageIdentifiersInterface;
use Magento\Framework\Exception\LocalizedException;
use Zend_Db_Statement_Exception;
use Aligent\Sitemap\Model\Config\Data as AligentSitemapConfig;
use Aligent\Sitemap\Model\Config\ConfigReaderInterface as AligentSitemapConfigReaderInterface;
use Magento\Sitemap\Model\ResourceModel\Cms\Page;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\DataObject;
Expand All @@ -22,13 +22,13 @@ class GetValidCmsPagesForSitemap
/**
* @param GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers
* @param MetadataPool $metadataPool
* @param AligentSitemapConfig $aligentSitemapConfig
* @param AligentSitemapConfigReaderInterface $aligentSitemapConfig
* @param Page $page
*/
public function __construct(
private readonly GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers,
private readonly MetadataPool $metadataPool,
private readonly AligentSitemapConfig $aligentSitemapConfig,
private readonly AligentSitemapConfigReaderInterface $aligentSitemapConfig,
private readonly Page $page
) {
}
Expand Down
Loading