-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add General urls change filter with shop main url
Signed-off-by: Anton Fedurtsya <[email protected]>
- Loading branch information
Showing
16 changed files
with
228 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Sitemap\ChangeFilter\General; | ||
|
||
use FreshAdvance\Sitemap\ChangeFilter\Shared\BaseChangeFilter; | ||
use FreshAdvance\Sitemap\Integration\DataType\ObjectUrl; | ||
use FreshAdvance\Sitemap\Settings\ShopSettingsInterface; | ||
|
||
class GeneralChangeFilter extends BaseChangeFilter | ||
{ | ||
public function __construct( | ||
string $objectType, | ||
protected ShopSettingsInterface $shopSettings, | ||
) { | ||
parent::__construct($objectType); | ||
} | ||
|
||
public function getUpdatedUrls(int $limit): \Generator | ||
{ | ||
yield new ObjectUrl( | ||
objectId: "main", | ||
objectType: $this->getObjectType(), | ||
location: $this->prepareUrl('/'), | ||
modified: new \DateTime() | ||
); | ||
} | ||
|
||
protected function prepareUrl(string $url): string | ||
{ | ||
return implode("/", [ | ||
rtrim($this->shopSettings->getShopUrl()), | ||
$url | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
parameters: | ||
sitemap.object_type.general: 'general' | ||
|
||
services: | ||
|
||
_defaults: | ||
public: false | ||
autowire: true | ||
|
||
FreshAdvance\Sitemap\ChangeFilter\General\GeneralChangeFilter: | ||
arguments: | ||
$objectType: '%sitemap.object_type.general%' | ||
tags: | ||
- 'sitemap.change_filter' | ||
|
||
FreshAdvance\Sitemap\ChangeFilter\General\GeneralUrlType: | ||
class: FreshAdvance\Sitemap\Url\DataType\UrlType | ||
arguments: | ||
$objectType: '%sitemap.object_type.general%' | ||
$changeFrequency: 'daily' | ||
$priority: 0.85 | ||
tags: | ||
- 'sitemap.page_type_configuration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Sitemap\ChangeFilter\Shared; | ||
|
||
use FreshAdvance\Sitemap\Integration\Contract\ChangeFilterInterface; | ||
|
||
abstract class BaseChangeFilter implements ChangeFilterInterface | ||
{ | ||
public function __construct( | ||
protected string $objectType | ||
) { | ||
} | ||
|
||
public function getObjectType(): string | ||
{ | ||
return $this->objectType; | ||
} | ||
|
||
abstract public function getUpdatedUrls(int $limit): iterable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
imports: | ||
- { resource: Category/services.yaml } | ||
- { resource: Content/services.yaml } | ||
- { resource: General/services.yaml } | ||
- { resource: Product/services.yaml } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Sitemap\Tests\Integration\Service; | ||
|
||
use FreshAdvance\Sitemap\Integration\Service\FilterFactoryInterface; | ||
use FreshAdvance\Sitemap\Tests\Integration\IntegrationTestCase; | ||
|
||
/** | ||
* @covers \FreshAdvance\Sitemap\Integration\Service\FilterFactory | ||
*/ | ||
class FilterFactoryTest extends IntegrationTestCase | ||
{ | ||
public function testInitialization(): void | ||
{ | ||
$sut = $this->get(FilterFactoryInterface::class); | ||
$this->assertInstanceOf(FilterFactoryInterface::class, $sut); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Integration/Url/DataTypeFactory/UrlTypeFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Sitemap\Tests\Integration\Url\DataTypeFactory; | ||
|
||
use FreshAdvance\Sitemap\Tests\Integration\IntegrationTestCase; | ||
use FreshAdvance\Sitemap\Url\DataTypeFactory\UrlTypeFactoryInterface; | ||
|
||
/** | ||
* @covers \FreshAdvance\Sitemap\Url\DataTypeFactory\UrlTypeFactory | ||
*/ | ||
class UrlTypeFactoryTest extends IntegrationTestCase | ||
{ | ||
public function testInitialization(): void | ||
{ | ||
$sut = $this->get(UrlTypeFactoryInterface::class); | ||
$this->assertInstanceOf(UrlTypeFactoryInterface::class, $sut); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Unit/ChangeFilter/General/GeneralChangeFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangeFilter\General; | ||
|
||
use FreshAdvance\Sitemap\ChangeFilter\General\GeneralChangeFilter; | ||
use FreshAdvance\Sitemap\Integration\DataType\ObjectUrl; | ||
use FreshAdvance\Sitemap\Settings\ShopSettingsInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GeneralChangeFilterTest extends TestCase | ||
{ | ||
public function testGetUpdatedUrls(): void | ||
{ | ||
$sut = new GeneralChangeFilter( | ||
objectType: "someObjectType", | ||
shopSettings: $shopSettingsStub = $this->createStub(ShopSettingsInterface::class) | ||
); | ||
|
||
$shopUrlExample = "shopUrlStart"; | ||
$shopSettingsStub->method('getShopUrl')->willReturn($shopUrlExample); | ||
|
||
$count = 0; | ||
foreach ($sut->getUpdatedUrls(1000) as $oneObjectUrl) { | ||
$this->assertInstanceOf(ObjectUrl::class, $oneObjectUrl); | ||
$this->assertStringStartsWith($shopUrlExample, $oneObjectUrl->getLocation()); | ||
$count++; | ||
} | ||
|
||
$this->assertTrue($count > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangeFilter\Shared; | ||
|
||
use FreshAdvance\Sitemap\ChangeFilter\Shared\BaseChangeFilter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \FreshAdvance\Sitemap\ChangeFilter\Shared\BaseChangeFilter | ||
*/ | ||
class BaseChangeFilterTest extends TestCase | ||
{ | ||
public function testGetObjectType(): void | ||
{ | ||
$objectType = uniqid(); | ||
|
||
$sut = new class($objectType) extends BaseChangeFilter { | ||
public function getUpdatedUrls(int $limit): iterable | ||
{ | ||
} | ||
}; | ||
|
||
$this->assertSame($objectType, $sut->getObjectType()); | ||
} | ||
} |