Passed
Push — master ( ed6c8e...268125 )
by Aimeos
03:53
created

StandardTest::testGetBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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