Passed
Push — master ( 8ffe39...7659ed )
by Aimeos
03:48
created

StandardTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
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\Product\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( 'product' ) ?: $fs->mkdir( 'product' );
25
		$fs->writef( 'product/product_1.xml', __DIR__ . '/_testfiles/product_1.xml' );
26
		$fs->writef( 'product/product_2.xml', __DIR__ . '/_testfiles/product_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\Product\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( 'Product import XML', $this->object->getName() );
59
	}
60
61
62
	public function testGetDescription()
63
	{
64
		$text = 'Imports new and updates existing products from XML files';
65
		$this->assertEquals( $text, $this->object->getDescription() );
66
	}
67
68
69
	public function testRun()
70
	{
71
		$this->object->run();
72
73
		$domains = ['attribute', 'catalog', 'media', 'media/property', 'price', 'product', 'product/property', 'supplier', 'text'];
74
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
75
		$item = $manager->find( 'unittest-xml', $domains );
76
		$manager->delete( $item->getId() );
77
78
		$this->assertEquals( 'default', $item->getType() );
79
		$this->assertEquals( 'Test product', $item->getLabel() );
80
		$this->assertEquals( ['css' => 'new'], $item->getConfig() );
81
		$this->assertEquals( 1, count( $item->getRefItems( 'attribute' ) ) );
82
		$this->assertEquals( 1, count( $item->getRefItems( 'catalog' ) ) );
83
		$this->assertEquals( 1, count( $item->getRefItems( 'product' ) ) );
84
		$this->assertEquals( 1, count( $item->getRefItems( 'media' ) ) );
85
		$this->assertEquals( 1, count( $item->getRefItems( 'price' ) ) );
86
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
87
		$this->assertEquals( 1, count( $item->getPropertyItems() ) );
88
		$this->assertEquals( 1, count( $item->getRefItems( 'media' )->first()->getPropertyItems() ) );
89
		$this->assertEquals( 1, count( $item->getRefItems( 'media' )->first()->getListItems( 'attribute' ) ) );
90
		$this->assertEquals( 1, count( $item->getRefItems( 'price' )->first()->getListItems( 'attribute' ) ) );
91
		$this->assertEquals( 1, count( $item->getRefItems( 'text' )->first()->getListItems( 'attribute' ) ) );
92
	}
93
}
94