StandardTest::testGetDescription()   A
last analyzed

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-2025
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Customer\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( 'customer/unittest' ) ?: $fs->mkdir( 'customer/unittest' );
25
		$fs->writef( 'customer/unittest/customer_1.xml', __DIR__ . '/_testfiles/customer_1.xml' );
26
		$fs->writef( 'customer/unittest/customer_2.xml', __DIR__ . '/_testfiles/customer_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
		$this->context = \TestHelper::context();
41
		$this->aimeos = \TestHelper::getAimeos();
42
43
		$this->object = new \Aimeos\Controller\Jobs\Customer\Import\Xml\Standard( $this->context, $this->aimeos );
44
	}
45
46
47
	protected function tearDown() : void
48
	{
49
		unset( $this->object, $this->context, $this->aimeos );
50
	}
51
52
53
	public function testGetName()
54
	{
55
		$this->assertEquals( 'Customer import XML', $this->object->getName() );
56
	}
57
58
59
	public function testGetDescription()
60
	{
61
		$text = 'Imports new and updates existing customers from XML files';
62
		$this->assertEquals( $text, $this->object->getDescription() );
63
	}
64
65
66
	public function testRun()
67
	{
68
		$this->object->run();
69
70
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
71
		$item = $manager->find( '[email protected]', ['customer/address', 'customer/property', 'media', 'text'] );
72
		$manager->delete( $item->getId() );
73
74
		$this->assertEquals( 'Test user', $item->getLabel() );
75
		$this->assertEquals( 1, count( $item->getPropertyItems() ) );
76
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
77
		$this->assertEquals( 1, count( $item->getRefItems( 'media' ) ) );
78
		$this->assertEquals( 'ms', $item->getPaymentAddress()->getSalutation() );
79
		$this->assertEquals( 'Example street', $item->getPaymentAddress()->getAddress1() );
80
		$this->assertEquals( 'ms', $item->getAddressItems()->first()->getSalutation() );
81
	}
82
}
83