Passed
Pull Request — master (#12)
by
unknown
01:56
created

StandardTest::testRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 24
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2019
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Catalog\Export\Sitemap;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $object;
15
	private $context;
16
	private $aimeos;
17
18
19
	protected function setUp()
20
	{
21
		\Aimeos\MShop::cache( true );
22
23
		$this->context = \TestHelperJobs::getContext();
24
		$this->aimeos = \TestHelperJobs::getAimeos();
25
26
		$this->object = new \Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Standard( $this->context, $this->aimeos );
27
	}
28
29
30
	protected function tearDown()
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->getConfig()->set( 'controller/jobs/catalog/export/sitemap/max-items', 5 );
53
54
		$this->object->run();
55
56
		$ds = DIRECTORY_SEPARATOR;
57
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz' );
58
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz' );
59
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz' );
60
61
		$file1 = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz', 'rb' ), 0x1000 );
62
		$file2 = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz', 'rb' ), 0x1000 );
63
		$index = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz', 'rb' ), 0x1000 );
64
65
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz' );
66
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz' );
67
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz' );
68
69
		$this->assertContains( 'Kaffee', $file1 );
70
		$this->assertContains( 'Misc', $file2 );
71
72
		$this->assertContains( 'aimeos-catalog-sitemap-1.xml.gz', $index );
73
		$this->assertContains( 'aimeos-catalog-sitemap-2.xml.gz', $index );
74
	}
75
76
	public function testRunEmptyLocation()
77
	{
78
		$this->context->getConfig()->set( 'controller/jobs/catalog/export/sitemap/location', '' );
79
80
		$this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception');
81
82
		$this->object->run();
83
	}
84
85
	public function testRunNoLocation()
86
	{
87
		$this->context->getConfig()->set( 'controller/jobs/catalog/export/sitemap/location', null );
88
89
		$this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception');
90
91
		$this->object->run();
92
	}
93
}