Passed
Push — master ( b5b91f...783ab4 )
by Aimeos
01:53
created

StandardTest::testGetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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), 2019
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Stock\Import\Csv;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
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
		$config = $this->context->getConfig();
26
27
		$config->set( 'controller/jobs/stock/import/csv/location', __DIR__ . '/_testfiles' );
28
29
		$this->object = new \Aimeos\Controller\Jobs\Stock\Import\Csv\Standard( $this->context, $this->aimeos );
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		\Aimeos\MShop::cache( false );
36
		unset( $this->object );
37
	}
38
39
40
	public function testGetName()
41
	{
42
		$this->assertEquals( 'Stock import CSV', $this->object->getName() );
43
	}
44
45
46
	public function testGetDescription()
47
	{
48
		$text = 'Imports new and updates existing stocks from CSV files';
49
		$this->assertEquals( $text, $this->object->getDescription() );
50
	}
51
52
53
	public function testRun()
54
	{
55
		$this->object->run();
56
57
		$map = $ids = [];
58
		$manager = \Aimeos\MShop::create( $this->context, 'stock' );
59
60
		$search = $manager->createSearch();
61
		$search->setConditions( $search->compare( '==', 'stock.productcode', ['unittest-csv', 'unittest-csv2'] ) );
62
63
		foreach( $manager->searchItems( $search ) as $item )
64
		{
65
			$map[$item->getProductCode()] = $item;
66
			$ids[] = $item->getId();
67
		}
68
69
		$this->assertEquals( 2, count( $map ) );
70
71
		$this->assertEquals( 'test', $map['unittest-csv']->getType() );
72
		$this->assertEquals( 10, $map['unittest-csv']->getStockLevel() );
73
		$this->assertEquals( '2000-01-01 00:00:00', $map['unittest-csv']->getDateBack() );
74
75
		$this->assertEquals( 'default', $map['unittest-csv2']->getType() );
76
		$this->assertEquals( null, $map['unittest-csv2']->getStockLevel() );
77
		$this->assertEquals( null, $map['unittest-csv2']->getDateBack() );
78
	}
79
}
80