1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Jobs\Coupon\Import\Csv\Code; |
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\Factory::setCache( true ); |
22
|
|
|
|
23
|
|
|
$this->context = \TestHelperJobs::getContext(); |
24
|
|
|
$this->aimeos = \TestHelperJobs::getAimeos(); |
25
|
|
|
$config = $this->context->getConfig(); |
26
|
|
|
|
27
|
|
|
$config->set( 'controller/jobs/product/import/csv/skip-lines', 1 ); |
28
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\Controller\Jobs\Coupon\Import\Csv\Code\Standard( $this->context, $this->aimeos ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
36
|
|
|
\Aimeos\MShop\Factory::clear(); |
37
|
|
|
|
38
|
|
|
unset( $this->object ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testGetName() |
43
|
|
|
{ |
44
|
|
|
$this->assertEquals( 'Coupon code import CSV', $this->object->getName() ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetDescription() |
49
|
|
|
{ |
50
|
|
|
$text = 'Imports new and updates existing coupon code from CSV files'; |
51
|
|
|
$this->assertEquals( $text, $this->object->getDescription() ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testRun() |
56
|
|
|
{ |
57
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' ); |
58
|
|
|
$coupon = $manager->saveItem( $manager->createItem()->setProvider( 'Example' ) ); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$dir = 'tmp/import/couponcode/unittest'; |
61
|
|
|
$filepath = $dir . '/' . $coupon->getId() . '.csv'; |
|
|
|
|
62
|
|
|
|
63
|
|
|
if( !is_dir( $dir ) && mkdir( 'tmp/import/couponcode/unittest', 0775, true ) === false ) { |
64
|
|
|
throw new \Exception( sprintf( 'Unable to create directory "%1$s"', $dir ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$content = 'code,count,start,end |
68
|
|
|
jobccimport1,3,2000-01-01 00:00:00, |
69
|
|
|
jobccimport2,5,,'; |
70
|
|
|
|
71
|
|
|
if( file_put_contents( $filepath, $content ) === false ) { |
72
|
|
|
throw new \Exception( sprintf( 'Unable to create file "%1$s"', $file ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->object->run(); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
unlink( $filepath ); |
79
|
|
|
|
80
|
|
|
$codeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon/code' ); |
81
|
|
|
$code1 = $codeManager->findItem( 'jobccimport1' ); |
82
|
|
|
$code2 = $codeManager->findItem( 'jobccimport2' ); |
83
|
|
|
|
84
|
|
|
$manager->deleteItem( $coupon->getId() ); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$this->assertEquals( 3, $code1->getCount() ); |
87
|
|
|
$this->assertEquals( '2000-01-01 00:00:00', $code1->getDateStart() ); |
88
|
|
|
$this->assertEquals( null, $code1->getDateEnd() ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( 5, $code2->getCount() ); |
91
|
|
|
$this->assertEquals( null, $code2->getDateStart() ); |
92
|
|
|
$this->assertEquals( null, $code2->getDateEnd() ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testRunException() |
97
|
|
|
{ |
98
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' ); |
99
|
|
|
$coupon = $manager->saveItem( $manager->createItem()->setProvider( 'Example' ) ); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$dir = 'tmp/import/couponcode/unittest'; |
102
|
|
|
$filepath = $dir . '/0.csv'; |
103
|
|
|
|
104
|
|
|
if( !is_dir( $dir ) && mkdir( 'tmp/import/couponcode/unittest', 0775, true ) === false ) { |
105
|
|
|
throw new \Exception( sprintf( 'Unable to create directory "%1$s"', $dir ) ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$content = 'code,count,start,end |
109
|
|
|
jobccimport1,,,'; |
110
|
|
|
|
111
|
|
|
if( file_put_contents( $filepath, $content ) === false ) { |
112
|
|
|
throw new \Exception( sprintf( 'Unable to create file "%1$s"', $file ) ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$this->object->run(); |
116
|
|
|
|
117
|
|
|
unlink( $filepath ); |
118
|
|
|
} |
119
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.