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\MShop\Service\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class SupplierTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $basket; |
16
|
|
|
private $context; |
17
|
|
|
private $servItem; |
18
|
|
|
private $mockProvider; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
|
25
|
|
|
$servManager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
26
|
|
|
$this->servItem = $servManager->createItem(); |
27
|
|
|
|
28
|
|
|
$this->mockProvider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Decorator\\Supplier' ) |
29
|
|
|
->disableOriginalConstructor()->getMock(); |
30
|
|
|
|
31
|
|
|
$this->basket = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context ) |
32
|
|
|
->getSubManager( 'base' )->createItem(); |
33
|
|
|
|
34
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Supplier( $this->mockProvider, $this->context, $this->servItem ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
protected function tearDown() |
39
|
|
|
{ |
40
|
|
|
unset( $this->object, $this->basket, $this->mockProvider, $this->servItem, $this->context ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testGetConfigFE() |
45
|
|
|
{ |
46
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperMShop::getContext() ); |
47
|
|
|
$orderBaseManager = $orderManager->getSubManager( 'base' ); |
48
|
|
|
$search = $orderManager->createSearch(); |
49
|
|
|
$expr = array( |
50
|
|
|
$search->compare( '==', 'order.type', \Aimeos\MShop\Order\Item\Base::TYPE_WEB ), |
51
|
|
|
$search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ) |
52
|
|
|
); |
53
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
54
|
|
|
$orderItems = $orderManager->searchItems( $search ); |
55
|
|
|
|
56
|
|
|
if( ( $order = reset( $orderItems ) ) === false ) { |
57
|
|
|
throw new \RuntimeException( sprintf( 'No Order found with statuspayment "%1$s" and type "%2$s"', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, \Aimeos\MShop\Order\Item\Base::TYPE_WEB ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$basket = $orderBaseManager->load( $order->getBaseId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE ); |
61
|
|
|
$config = $this->object->getConfigFE( $basket ); |
62
|
|
|
|
63
|
|
|
$this->assertInternalType( 'array', $config['supplier.code']->getDefault() ); |
64
|
|
|
$this->assertEquals( 2, count( $config['supplier.code']->getDefault() ) ); |
65
|
|
|
|
66
|
|
|
foreach( $config['supplier.code']->getDefault() as $string ) { |
67
|
|
|
$this->assertGreaterThan( 100, strlen( $string ) ); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testCheckConfigFE() |
73
|
|
|
{ |
74
|
|
|
$this->mockProvider->expects( $this->once() ) |
75
|
|
|
->method( 'checkConfigFE' ) |
76
|
|
|
->will( $this->returnValue( [] ) ); |
77
|
|
|
|
78
|
|
|
$attributes = array( 'supplier.code' => 'unitCode001' ); |
79
|
|
|
$expected = array( 'supplier.code' => null ); |
80
|
|
|
|
81
|
|
|
$result = $this->object->checkConfigFE( $attributes ); |
82
|
|
|
|
83
|
|
|
$this->assertEquals( $expected, $result ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testCheckConfigFEwrongType() |
88
|
|
|
{ |
89
|
|
|
$this->mockProvider->expects( $this->once() ) |
90
|
|
|
->method( 'checkConfigFE' ) |
91
|
|
|
->will( $this->returnValue( [] ) ); |
92
|
|
|
|
93
|
|
|
$config = array( 'supplier.code' => -1 ); |
94
|
|
|
$result = $this->object->checkConfigFE( $config ); |
95
|
|
|
|
96
|
|
|
$this->assertArrayHasKey( 'supplier.code', $result ); |
97
|
|
|
$this->assertNotNull( $result['supplier.code'] ); |
98
|
|
|
} |
99
|
|
|
} |