Passed
Push — master ( 510396...fb4e88 )
by Aimeos
03:40
created

StandardTest::testGetSubClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Order\Transaction;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->view = \TestHelper::view();
22
		$this->context = \TestHelper::context();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Order\Transaction\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelper::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown() : void
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testCopy()
38
	{
39
		$this->view->item = $this->getOrderBaseItem();
40
41
		$result = $this->object->copy();
42
43
		$this->assertStringContainsString( 'item-transaction', $result );
44
	}
45
46
47
	public function testCreate()
48
	{
49
		$this->view->item = $this->getOrderBaseItem();
50
51
		$result = $this->object->create();
52
53
		$this->assertStringContainsString( 'item-transaction', $result );
54
	}
55
56
57
	public function testGet()
58
	{
59
		$this->view->item = $this->getOrderBaseItem();
60
61
		$result = $this->object->get();
62
63
		$this->assertStringContainsString( 'item-transaction', $result );
64
	}
65
66
67
	public function testSave()
68
	{
69
		$this->view->item = $this->getOrderBaseItem();
70
		$serviceId = current( $this->view->item->getService( 'payment' ) )->getId();
71
72
		$param = [
73
			'site' => 'unittest',
74
			'transaction' => [
75
				$serviceId => [
76
					'order.base.service.transaction.value' => 10,
77
					'order.base.service.transaction.costs' => 1,
78
				]
79
			],
80
		];
81
82
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
83
		$this->view->addHelper( 'param', $helper );
84
85
		$result = $this->object->save();
86
87
		$this->assertEmpty( $result );
88
	}
89
90
91
	public function testSavePayPal()
92
	{
93
		$this->view->item = $this->getOrderBaseItem( '13.50' );
94
		$serviceId = current( $this->view->item->getService( 'payment' ) )->getId();
95
96
		$param = [
97
			'site' => 'unittest',
98
			'transaction' => [
99
				$serviceId => [
100
					'order.base.service.transaction.value' => 10,
101
					'order.base.service.transaction.costs' => 1,
102
				]
103
			],
104
		];
105
106
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
107
		$this->view->addHelper( 'param', $helper );
108
109
		$this->expectException( \Aimeos\MShop\Service\Exception::class );
110
		$this->object->save();
111
	}
112
113
114
	public function testGetSubClient()
115
	{
116
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
117
		$this->object->getSubClient( 'unknown' );
118
	}
119
120
121
	protected function getViewNoRender()
122
	{
123
		$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
124
			->setConstructorArgs( array( [] ) )
125
			->setMethods( array( 'render', 'config' ) )
126
			->getMock();
127
128
		$view->item = $this->getOrderBaseItem();
0 ignored issues
show
Bug introduced by
Accessing item on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
129
130
		return $view;
131
	}
132
133
134
	protected function getOrderBaseItem( $value = '672.00' )
135
	{
136
		$manager = \Aimeos\MShop::create( $this->context, 'order/base' );
137
		$search = $manager->filter()->add( 'order.base.price', '==', $value );
138
139
		return $manager->search( $search, ['order/base/service'] )
140
			->first( new \RuntimeException( 'No order base item found' ) );
141
	}
142
}
143