Passed
Push — master ( 659531...28cbe9 )
by Aimeos
03:02
created

StandardTest::setUpBeforeClass()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2021
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Attribute\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 = \TestHelperJobs::context();
22
23
		$fs = $context->fs( 'fs-media' );
24
		$fs->has( 'path/to' ) ?: $fs->mkdir( 'path/to' );
25
		$fs->write( 'path/to/file2.jpg', 'test' );
26
		$fs->write( 'path/to/file.jpg', 'test' );
27
28
		$fs = $context->fs( 'fs-mimeicon' );
29
		$fs->write( 'unknown.png', 'icon' );
30
	}
31
32
33
	protected function setUp() : void
34
	{
35
		$this->context = \TestHelperJobs::context();
36
		$this->aimeos = \TestHelperJobs::getAimeos();
37
38
		$config = $this->context->config();
39
		$config->set( 'controller/jobs/attribute/import/xml/location', __DIR__ . '/_testfiles' );
40
41
		$this->object = new \Aimeos\Controller\Jobs\Attribute\Import\Xml\Standard( $this->context, $this->aimeos );
42
	}
43
44
45
	protected function tearDown() : void
46
	{
47
		unset( $this->object, $this->context, $this->aimeos );
48
	}
49
50
51
	public function testGetName()
52
	{
53
		$this->assertEquals( 'Attribute import XML', $this->object->getName() );
54
	}
55
56
57
	public function testGetDescription()
58
	{
59
		$text = 'Imports new and updates existing attributes from XML files';
60
		$this->assertEquals( $text, $this->object->getDescription() );
61
	}
62
63
64
	public function testRun()
65
	{
66
		$this->object->run();
67
68
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
69
		$item = $manager->find( 'unittest-xml', ['attribute/property', 'media', 'price', 'text'], 'product', 'color' );
70
		$manager->delete( $item->getId() );
71
72
		$this->assertEquals( 'Test attribute 2', $item->getLabel() );
73
		$this->assertEquals( 1, count( $item->getRefItems( 'media' ) ) );
74
		$this->assertEquals( 1, count( $item->getRefItems( 'price' ) ) );
75
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
76
		$this->assertEquals( 1, count( $item->getPropertyItems() ) );
77
	}
78
}
79