Passed
Push — master ( 43699b...cfa055 )
by Aimeos
04:02
created

StandardTest::getCustomerItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 */
8
9
10
namespace Aimeos\Client\Html\Account\History\Detail;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $context;
17
	private $view;
18
19
20
	protected function setUp() : void
21
	{
22
		$this->context = \TestHelperHtml::context();
23
24
		$this->view = \TestHelperHtml::view();
25
		$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order/base' )->create();
26
27
		$this->object = new \Aimeos\Client\Html\Account\History\Detail\Standard( $this->context );
28
		$this->object->setView( $this->view );
29
	}
30
31
32
	protected function tearDown() : void
33
	{
34
		unset( $this->object, $this->context, $this->view );
35
	}
36
37
38
	public function testBody()
39
	{
40
		$customer = $this->getCustomerItem( '[email protected]' );
41
		$this->context->setUserId( $customer->getId() );
42
43
		$this->view = \TestHelperHtml::view();
44
		$param = array(
45
			'his_action' => 'detail',
46
			'his_id' => $this->getOrderItem( $customer->getId() )->getId()
47
		);
48
49
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
50
		$this->view->addHelper( 'param', $helper );
51
52
		$this->object->setView( $this->object->data( $this->view ) );
53
54
		$output = $this->object->body();
55
56
		$this->assertStringStartsWith( '<div class="account-history-detail common-summary', $output );
57
58
		$this->assertStringContainsString( 'Our Unittest', $output );
59
		$this->assertStringContainsString( 'Example company', $output );
60
61
		$this->assertStringContainsString( '<h4>unitdeliverycode</h4>', $output );
62
		$this->assertStringContainsString( '<h4>unitpaymentcode</h4>', $output );
63
64
		$this->assertStringContainsString( '>1234<', $output );
65
		$this->assertStringContainsString( 'This is a comment', $output );
66
67
		$this->assertStringContainsString( 'Cafe Noire Expresso', $output );
68
		$this->assertStringContainsString( 'Cafe Noire Cappuccino', $output );
69
		$this->assertStringContainsString( 'Unittest: Monetary rebate', $output );
70
		$this->assertRegExp( '#<div class="price.+55.00 EUR</div>#', $output );
71
		$this->assertRegExp( '#<div class="quantity.+14 articles</div>#', $output );
72
	}
73
74
75
	public function testGetSubClientInvalid()
76
	{
77
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
78
		$this->object->getSubClient( 'invalid', 'invalid' );
79
	}
80
81
82
	public function testGetSubClientInvalidName()
83
	{
84
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
85
		$this->object->getSubClient( '$$$', '$$$' );
86
	}
87
88
89
	/**
90
	 * @param string $code
91
	 */
92
	protected function getCustomerItem( $code )
93
	{
94
		$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $this->context );
95
		$search = $manager->filter();
96
		$search->setConditions( $search->compare( '==', 'customer.code', $code ) );
97
98
		if( ( $item = $manager->search( $search )->first() ) === null ) {
99
			throw new \RuntimeException( sprintf( 'No customer item with code "%1$s" found', $code ) );
100
		}
101
102
		return $item;
103
	}
104
105
106
	protected function getOrderItem( $customerid )
107
	{
108
		$manager = \Aimeos\MShop\Order\Manager\Factory::create( $this->context );
109
		$search = $manager->filter( true );
110
		$expr = array(
111
			$search->getConditions(),
112
			$search->compare( '==', 'order.base.customerid', $customerid )
113
		);
114
		$search->setConditions( $search->and( $expr ) );
115
116
		if( ( $item = $manager->search( $search )->first() ) === null ) {
117
			throw new \RuntimeException( sprintf( 'No order item for customer with ID "%1$s" found', $customerid ) );
118
		}
119
120
		return $item;
121
	}
122
}
123