|
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
|
|
|
|