This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,058 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\SitemapBundle\Tests\Action; | ||
|
||
use Core23\SitemapBundle\Action\SitemapXMLAction; | ||
use Core23\SitemapBundle\Generator\SitemapGeneratorInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SitemapXMLActionTest extends TestCase | ||
{ | ||
public function testExecute(): void | ||
{ | ||
$generator = $this->prophesize(SitemapGeneratorInterface::class); | ||
$generator->toXML() | ||
->willReturn('<xml></xml>') | ||
; | ||
|
||
$action = new SitemapXMLAction($generator->reveal()); | ||
|
||
$response = $action(); | ||
|
||
$this->assertSame('text/xml', $response->headers->get('Content-Type')); | ||
$this->assertSame('<xml></xml>', $response->getContent()); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\SitemapBundle\Tests\Definition; | ||
|
||
use Core23\SitemapBundle\Definition\DefintionManager; | ||
use Core23\SitemapBundle\Definition\DefintionManagerInterface; | ||
use Core23\SitemapBundle\Definition\SitemapDefinition; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DefinitionManagerTest extends TestCase | ||
{ | ||
public function testItIsInstantiable(): void | ||
{ | ||
$definition = new DefintionManager(); | ||
|
||
$this->assertInstanceOf(DefintionManagerInterface::class, $definition); | ||
} | ||
|
||
public function testAddDefintion(): void | ||
{ | ||
$definition = new DefintionManager(); | ||
$definition->addDefinition('foo.definition', [ | ||
'foo' => 'bar', | ||
]); | ||
|
||
foreach ($definition->getAll() as $id => $item) { | ||
$this->assertInstanceOf(SitemapDefinition::class, $item); | ||
$this->assertSame('foo.definition', $id); | ||
$this->assertSame([ | ||
'foo' => 'bar', | ||
], $item->getSettings()); | ||
} | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\SitemapBundle\Tests\Definition; | ||
|
||
use Core23\SitemapBundle\Definition\SitemapDefinition; | ||
use Core23\SitemapBundle\Definition\SitemapDefinitionInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SitemapDefintionTest extends TestCase | ||
{ | ||
public function testItIsInstantiable(): void | ||
{ | ||
$definition = new SitemapDefinition('acme.sitemap'); | ||
|
||
$this->assertInstanceOf(SitemapDefinitionInterface::class, $definition); | ||
$this->assertSame('acme.sitemap', $definition->getType()); | ||
$this->assertSame('acme.sitemap', $definition->toString()); | ||
$this->assertSame([], $definition->getSettings()); | ||
} | ||
|
||
public function testSetting(): void | ||
{ | ||
$definition = new SitemapDefinition('acme.sitemap'); | ||
$definition->setSettings([ | ||
'foo'=> 'bar', | ||
]); | ||
|
||
$this->assertSame('bar', $definition->getSetting('foo')); | ||
} | ||
|
||
public function testSettingWithDefault(): void | ||
{ | ||
$definition = new SitemapDefinition('acme.sitemap'); | ||
|
||
$this->assertSame('baz', $definition->getSetting('foo', 'baz')); | ||
} | ||
|
||
public function testTtl(): void | ||
{ | ||
$definition = new SitemapDefinition('acme.sitemap', [ | ||
'use_cache' => true, | ||
'ttl' => 90, | ||
]); | ||
|
||
$this->assertSame(90, $definition->getTtl()); | ||
} | ||
|
||
public function testTtlDefault(): void | ||
{ | ||
$definition = new SitemapDefinition('acme.sitemap'); | ||
|
||
$this->assertSame(0, $definition->getTtl()); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
tests/DependencyInjection/Compiler/SitemapCompilerPassTest.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,124 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\SitemapBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Core23\SitemapBundle\Definition\DefintionManagerInterface; | ||
use Core23\SitemapBundle\DependencyInjection\Compiler\SitemapCompilerPass; | ||
use Core23\SitemapBundle\Sitemap\SitemapServiceManagerInterface; | ||
use Core23\SitemapBundle\Sitemap\StaticSitemapService; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class SitemapCompilerPassTest extends TestCase | ||
{ | ||
private $serviceManager; | ||
|
||
private $definitionManager; | ||
|
||
/** | ||
* @var ContainerBuilder | ||
*/ | ||
private $container; | ||
|
||
protected function setUp() | ||
{ | ||
$this->serviceManager = $this->prophesize(Definition::class); | ||
$this->serviceManager->hasTag('core23.sitemap') | ||
->willReturn(false) | ||
; | ||
$this->definitionManager = $this->prophesize(Definition::class); | ||
$this->definitionManager->hasTag('core23.sitemap') | ||
->willReturn(false) | ||
; | ||
|
||
$this->container = new ContainerBuilder(); | ||
$this->container->setDefinition(SitemapServiceManagerInterface::class, $this->serviceManager->reveal()); | ||
$this->container->setDefinition(DefintionManagerInterface::class, $this->definitionManager->reveal()); | ||
} | ||
|
||
public function testProcess(): void | ||
{ | ||
$this->serviceManager->addMethodCall('addSitemap', Argument::that(function ($args) { | ||
return 'acme.sitemap' === $args[0] && $args[1] instanceof Reference; | ||
})) | ||
->shouldBeCalled() | ||
; | ||
|
||
$this->definitionManager->addMethodCall('addDefinition', [ | ||
'acme.sitemap', | ||
]) | ||
->shouldBeCalled() | ||
; | ||
|
||
$sitemapDefinition = new Definition(); | ||
$sitemapDefinition->addTag('core23.sitemap'); | ||
|
||
$this->container->setParameter('core23_sitemap.static_urls', []); | ||
$this->container->setDefinition('acme.sitemap', $sitemapDefinition); | ||
|
||
$compiler = new SitemapCompilerPass(); | ||
$compiler->process($this->container); | ||
|
||
$this->assertTrue($sitemapDefinition->isPublic()); | ||
} | ||
|
||
public function testProcessWithNoServices(): void | ||
{ | ||
$this->container->setParameter('core23_sitemap.static_urls', []); | ||
|
||
$compiler = new SitemapCompilerPass(); | ||
$compiler->process($this->container); | ||
|
||
$this->assertTrue(true); | ||
} | ||
|
||
public function testProcessWithStaticUrls(): void | ||
{ | ||
$this->definitionManager->addMethodCall('addDefinition', [ | ||
StaticSitemapService::class, | ||
[ | ||
[ | ||
'url' => 'http://example.com', | ||
'priority' => 100, | ||
'changefreq' => 'daily', | ||
], | ||
], | ||
]) | ||
->shouldBeCalled() | ||
; | ||
|
||
$this->container->setParameter('core23_sitemap.static_urls', [ | ||
'static' => [ | ||
[ | ||
'url' => 'http://example.com', | ||
'priority' => 100, | ||
'changefreq' => 'daily', | ||
], | ||
], | ||
]); | ||
|
||
$compiler = new SitemapCompilerPass(); | ||
$compiler->process($this->container); | ||
} | ||
|
||
public function testProcessWithEmptyGroups(): void | ||
{ | ||
$this->container->setParameter('core23_sitemap.static_urls', []); | ||
|
||
$compiler = new SitemapCompilerPass(); | ||
$compiler->process($this->container); | ||
|
||
$this->serviceManager->addMethodCall(Argument::any())->shouldNotBeCalled(); | ||
$this->definitionManager->addMethodCall(Argument::any())->shouldNotBeCalled(); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\SitemapBundle\Tests\DependencyInjection; | ||
|
||
use Core23\SitemapBundle\DependencyInjection\Configuration; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Config\Definition\Processor; | ||
|
||
class ConfigurationTest extends TestCase | ||
{ | ||
public function testOptions(): void | ||
{ | ||
$processor = new Processor(); | ||
|
||
$config = $processor->processConfiguration(new Configuration(), [[ | ||
]]); | ||
|
||
$expected = [ | ||
'static' => [ | ||
], | ||
'cache' => [ | ||
'service' => null, | ||
], | ||
]; | ||
|
||
$this->assertSame($expected, $config); | ||
} | ||
|
||
public function testCronOptions(): void | ||
{ | ||
$processor = new Processor(); | ||
|
||
$config = $processor->processConfiguration(new Configuration(), [[ | ||
'cache' => [ | ||
'service' => 'acme.foo.service', | ||
], | ||
'static' => [ | ||
[ | ||
'url' => 'http://example.com', | ||
'priority' => 100, | ||
'changefreq' => 'daily', | ||
], | ||
], | ||
]]); | ||
|
||
$expected = [ | ||
'cache' => [ | ||
'service' => 'acme.foo.service', | ||
], | ||
'static' => [ | ||
[ | ||
'url' => 'http://example.com', | ||
'priority' => 100, | ||
'changefreq' => 'daily', | ||
], | ||
], | ||
]; | ||
|
||
$this->assertArraySubset($expected, $config); | ||
} | ||
} |
Oops, something went wrong.