StandardTest::testBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
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-2025
7
 */
8
9
10
namespace Aimeos\Client\Html\Checkout\Standard\Delivery;
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
		\Aimeos\Controller\Frontend::cache( true );
23
		\Aimeos\MShop::cache( true );
24
25
		$this->view = \TestHelper::view();
26
		$this->context = \TestHelper::context();
27
28
		$this->object = new \Aimeos\Client\Html\Checkout\Standard\Delivery\Standard( $this->context );
29
		$this->object->setView( $this->view );
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		\Aimeos\Controller\Frontend::create( $this->context, 'basket' )->clear();
36
		\Aimeos\Controller\Frontend::cache( false );
37
		\Aimeos\MShop::cache( false );
38
39
		unset( $this->object, $this->context, $this->view );
40
	}
41
42
43
	public function testBody()
44
	{
45
		$this->view = \TestHelper::view();
46
		$this->view->standardStepActive = 'delivery';
47
		$this->view->standardSteps = array( 'before', 'delivery', 'after' );
48
		$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order' )->create();
49
		$this->object->setView( $this->object->data( $this->view ) );
50
51
		$output = $this->object->body();
52
		$this->assertStringStartsWith( '<div class="section checkout-standard-delivery">', $output );
53
54
		$this->assertGreaterThan( 0, count( $this->view->deliveryServices ) );
55
	}
56
57
58
	public function testBodyOtherStep()
59
	{
60
		$this->view = \TestHelper::view();
61
		$this->object->setView( $this->object->data( $this->view ) );
62
63
		$output = $this->object->body();
64
		$this->assertEquals( '', $output );
65
	}
66
67
68
	public function testInit()
69
	{
70
		$this->object->init();
71
72
		$this->assertEquals( 'delivery', $this->view->get( 'standardStepActive' ) );
73
	}
74
75
76
	public function testInitExistingId()
77
	{
78
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
79
		$search = $manager->filter();
80
		$search->setConditions( $search->compare( '==', 'service.code', 'unitdeliverycode' ) );
81
82
		if( ( $service = $manager->search( $search )->first() ) === null ) {
83
			throw new \RuntimeException( 'Service item not found' );
84
		}
85
86
		$this->view = \TestHelper::view();
87
88
		$param = array(
89
			'c_deliveryoption' => $service->getId(),
90
		);
91
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
92
		$this->view->addHelper( 'param', $helper );
93
94
		$this->object->setView( $this->view );
95
96
		$this->object->init();
97
98
		$basket = \Aimeos\Controller\Frontend::create( $this->context, 'basket' )->get();
99
		$this->assertEquals( 'unitdeliverycode', $basket->getService( 'delivery', 0 )->getCode() );
100
	}
101
102
103
	public function testInitInvalidId()
104
	{
105
		$this->view = \TestHelper::view();
106
107
		$param = array( 'c_deliveryoption' => -1 );
108
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
109
		$this->view->addHelper( 'param', $helper );
110
111
		$this->object->setView( $this->view );
112
113
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
114
		$this->object->init();
115
	}
116
117
118
	public function testInitNotExistingAttributes()
119
	{
120
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
121
		$search = $manager->filter();
122
		$search->setConditions( $search->compare( '==', 'service.code', 'unitdeliverycode' ) );
123
124
		if( ( $service = $manager->search( $search )->first() ) === null ) {
125
			throw new \RuntimeException( 'Service item not found' );
126
		}
127
128
		$this->view = \TestHelper::view();
129
130
		$param = array(
131
			'c_deliveryoption' => $service->getId(),
132
			'c_delivery' => array(
133
				$service->getId() => array(
134
					'notexisting' => 'invalid value',
135
				),
136
			),
137
		);
138
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
139
		$this->view->addHelper( 'param', $helper );
140
141
		$this->object->setView( $this->view );
142
143
		$this->expectException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' );
144
		$this->object->init();
145
	}
146
}
147