Passed
Push — master ( 8b1641...595372 )
by Aimeos
03:00
created

StandardTest::testGetDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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-2022
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Catalog\Import\Xml;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $aimeos;
17
18
19
	public static function setUpBeforeClass() : void
20
	{
21
		$context = \TestHelper::context();
22
23
		$fs = $context->fs( 'fs-import' );
24
		$fs->has( 'catalog' ) ?: $fs->mkdir( 'catalog' );
25
		$fs->writef( 'catalog/catalog_1.xml', __DIR__ . '/_testfiles/catalog_1.xml' );
26
		$fs->writef( 'catalog/catalog_2.xml', __DIR__ . '/_testfiles/catalog_2.xml' );
27
28
		$fs = $context->fs( 'fs-media' );
29
		$fs->has( 'path/to' ) ?: $fs->mkdir( 'path/to' );
30
		$fs->write( 'path/to/file2.jpg', 'test' );
31
		$fs->write( 'path/to/file.jpg', 'test' );
32
33
		$fs = $context->fs( 'fs-mimeicon' );
34
		$fs->write( 'unknown.png', 'icon' );
35
	}
36
37
38
	protected function setUp() : void
39
	{
40
		\Aimeos\MShop::cache( true );
41
42
		$this->context = \TestHelper::context();
43
		$this->aimeos = \TestHelper::getAimeos();
44
45
		$this->object = new \Aimeos\Controller\Jobs\Catalog\Import\Xml\Standard( $this->context, $this->aimeos );
46
	}
47
48
49
	protected function tearDown() : void
50
	{
51
		\Aimeos\MShop::cache( false );
52
		unset( $this->object, $this->context, $this->aimeos );
53
	}
54
55
56
	public function testGetName()
57
	{
58
		$this->assertEquals( 'Catalog import XML', $this->object->getName() );
59
	}
60
61
62
	public function testGetDescription()
63
	{
64
		$text = 'Imports new and updates existing categories from XML files';
65
		$this->assertEquals( $text, $this->object->getDescription() );
66
	}
67
68
69
	public function testRun()
70
	{
71
		$this->object->run();
72
73
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
74
		$tree = $manager->getTree( $manager->find( 'unittest-xml' )->getId(), ['media', 'product', 'text'] );
75
		$manager->delete( $tree->getId() );
76
77
		$this->assertEquals( 'Test catalog', $tree->getLabel() );
78
		$this->assertEquals( ['css' => 'new'], $tree->getConfig() );
79
		$this->assertEquals( 2, count( $tree->getChildren() ) );
80
		$this->assertEquals( 1, count( $tree->getRefItems( 'text', null, null, false ) ) );
81
		$this->assertEquals( 'Test sub-category 3', $tree->getChild( 0 )->getLabel() );
82
		$this->assertEquals( 2, count( $tree->getChild( 0 )->getRefItems( 'product' ) ) );
83
		$this->assertEquals( 'Test sub-category 3-1', $tree->getChild( 0 )->getChild( 0 )->getLabel() );
84
	}
85
}
86