StandardTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 34
c 3
b 0
f 0
dl 0
loc 73
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetName() 0 3 1
A tearDown() 0 4 1
A testGetDescription() 0 4 1
A setUp() 0 8 1
A testRun() 0 26 1
A testRunEmptyBaseurl() 0 6 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Catalog\Export\Sitemap;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $aimeos;
17
18
19
	protected function setUp() : void
20
	{
21
		\Aimeos\MShop::cache( true );
22
23
		$this->context = \TestHelper::context();
24
		$this->aimeos = \TestHelper::getAimeos();
25
26
		$this->object = new \Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Standard( $this->context, $this->aimeos );
27
	}
28
29
30
	protected function tearDown() : void
31
	{
32
		\Aimeos\MShop::cache( false );
33
		$this->object = null;
34
	}
35
36
37
	public function testGetName()
38
	{
39
		$this->assertEquals( 'Catalog site map', $this->object->getName() );
40
	}
41
42
43
	public function testGetDescription()
44
	{
45
		$text = 'Creates a catalog site map for search engines';
46
		$this->assertEquals( $text, $this->object->getDescription() );
47
	}
48
49
50
	public function testRun()
51
	{
52
		$this->context->config()->set( 'controller/jobs/catalog/export/sitemap/max-items', 5 );
53
		$this->context->config()->set( 'resource/fs/baseurl', 'https://www.yourshop.com/' );
54
55
		$this->object->run();
56
57
		$ds = DIRECTORY_SEPARATOR;
58
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml' );
59
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml' );
60
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml' );
61
62
		$file1 = file_get_contents( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml' );
63
		$file2 = file_get_contents( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml' );
64
		$index = file_get_contents( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml' );
65
66
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml' );
67
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml' );
68
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml' );
69
70
		$this->assertStringContainsString( 'kaffee', $file1 );
71
		$this->assertStringContainsString( 'misc', $file1 );
72
		$this->assertStringContainsString( 'groups', $file2 );
73
74
		$this->assertStringContainsString( 'https://www.yourshop.com/aimeos-catalog-sitemap-1.xml', $index );
75
		$this->assertStringContainsString( 'https://www.yourshop.com/aimeos-catalog-sitemap-2.xml', $index );
76
	}
77
78
79
	public function testRunEmptyBaseurl()
80
	{
81
		$this->context->config()->set( 'resource/fs/baseurl', '' );
82
83
		$this->expectException( '\\Aimeos\\Controller\\Jobs\\Exception' );
84
		$this->object->run();
85
	}
86
}
87