|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2022 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Account\Subscription; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $view; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->context = \TestHelperHtml::context(); |
|
22
|
|
|
|
|
23
|
|
|
$this->view = \TestHelperHtml::view(); |
|
24
|
|
|
$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order/base' )->create(); |
|
25
|
|
|
|
|
26
|
|
|
$this->object = new \Aimeos\Client\Html\Account\Subscription\Standard( $this->context ); |
|
27
|
|
|
$this->object->setView( $this->view ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
protected function tearDown() : void |
|
32
|
|
|
{ |
|
33
|
|
|
unset( $this->object, $this->context, $this->view ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function testHeader() |
|
38
|
|
|
{ |
|
39
|
|
|
$output = $this->object->header(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertStringContainsString( '<link rel="stylesheet"', $output ); |
|
42
|
|
|
$this->assertStringContainsString( '<script defer', $output ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testBody() |
|
47
|
|
|
{ |
|
48
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'customer' ); |
|
49
|
|
|
$this->context->setUserId( $manager->find( '[email protected]' )->getId() ); |
|
50
|
|
|
|
|
51
|
|
|
$this->object->setView( $this->object->data( \TestHelperHtml::view() ) ); |
|
52
|
|
|
|
|
53
|
|
|
$output = $this->object->body(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertStringContainsString( '<section class="aimeos account-subscription"', $output ); |
|
56
|
|
|
$this->assertRegExp( '#<div class="subscription-item#', $output ); |
|
57
|
|
|
$this->assertRegExp( '#<h2 class="subscription-basic.*<span class="value[^<]+</span>.*</h2>#smU', $output ); |
|
58
|
|
|
$this->assertRegExp( '#<div class="subscription-interval.*<span class="value[^<]+</span>.*</div>#smU', $output ); |
|
59
|
|
|
$this->assertRegExp( '#<div class="subscription-datenext.*<span class="value[^<]+</span>.*</div>#smU', $output ); |
|
60
|
|
|
$this->assertRegExp( '#<div class="subscription-dateend.*<span class="value.*</span>.*</div>#smU', $output ); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertStringContainsString( 'Our Unittest', $output ); |
|
63
|
|
|
$this->assertStringContainsString( 'Example company', $output ); |
|
64
|
|
|
$this->assertStringContainsString( 'Cafe Noire Expresso', $output ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
public function testInit() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->view = \TestHelperHtml::view(); |
|
71
|
|
|
$param = array( |
|
72
|
|
|
'sub_action' => 'cancel', |
|
73
|
|
|
'sub_id' => $this->getSubscription()->getId() |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
77
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
78
|
|
|
|
|
79
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
|
80
|
|
|
|
|
81
|
|
|
$cntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Subscription\\Standard' ) |
|
82
|
|
|
->setConstructorArgs( [$this->context] ) |
|
83
|
|
|
->setMethods( ['cancel'] ) |
|
84
|
|
|
->getMock(); |
|
85
|
|
|
|
|
86
|
|
|
\Aimeos\Controller\Frontend\Subscription\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Subscription\\Standard', $cntlStub ); |
|
87
|
|
|
|
|
88
|
|
|
$cntlStub->expects( $this->once() )->method( 'cancel' ); |
|
89
|
|
|
|
|
90
|
|
|
$this->object->init(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
protected function getSubscription() |
|
95
|
|
|
{ |
|
96
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'subscription' ); |
|
97
|
|
|
$filter = $manager->filter()->add( 'subscription.dateend', '==', '2010-01-01' ); |
|
98
|
|
|
|
|
99
|
|
|
return $manager->search( $filter )->first( new \Exception( 'No subscription item found' ) ); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|