StandardTest::testCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2025
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Subscription;
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\Product\Subscription\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 testCreate()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
40
41
		$this->view->item = $manager->create();
42
		$result = $this->object->create();
43
44
		$this->assertStringContainsString( 'item-subscription', $result );
45
		$this->assertEmpty( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
52
53
		$this->view->item = $manager->find( 'CNE' );
54
		$result = $this->object->copy();
55
56
		$this->assertEmpty( $this->view->get( 'errors' ) );
57
		$this->assertStringContainsString( '&quot;attribute.label&quot;:&quot;product\/interval\/P1Y0M0W0D&quot;', $result );
58
	}
59
60
61
	public function testGet()
62
	{
63
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
64
65
		$this->view->item = $manager->find( 'CNE' );
66
		$result = $this->object->get();
67
68
		$this->assertEmpty( $this->view->get( 'errors' ) );
69
		$this->assertStringContainsString( '&quot;attribute.label&quot;:&quot;product\/interval\/P1Y0M0W0D&quot;', $result );
70
	}
71
72
73
	public function testSave()
74
	{
75
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
76
		$this->view->item = $manager->create();
77
78
		$param = array(
79
			'site' => 'unittest',
80
			'subscription' => array(
81
				array(
82
					'attribute.id' => '',
83
					'attribute.label' => '1 day',
84
					'attribute.code' => 'P0Y0M0W1D',
85
					'product.lists.id' => '',
86
				)
87
			),
88
		);
89
90
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
91
		$this->view->addHelper( 'param', $helper );
92
93
		$result = $this->object->save();
94
95
		$this->assertEmpty( $this->view->get( 'errors' ) );
96
		$this->assertEmpty( $result );
97
		$this->assertEquals( 1, count( $this->view->item->getListItems( 'attribute' ) ) );
98
		$this->assertEquals( 1, count( $this->view->item->getRefItems( 'attribute' ) ) );
99
	}
100
101
102
	public function testSaveException()
103
	{
104
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Subscription\Standard::class )
105
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
106
			->onlyMethods( array( 'fromArray' ) )
107
			->getMock();
108
109
		$object->expects( $this->once() )->method( 'fromArray' )
110
			->will( $this->throwException( new \RuntimeException() ) );
111
112
		$this->view = \TestHelper::view();
113
		$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create();
114
115
		$object->setView( $this->view );
116
117
		$this->expectException( \RuntimeException::class );
118
		$object->save();
119
	}
120
121
122
	public function testSaveMShopException()
123
	{
124
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Subscription\Standard::class )
125
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
126
			->onlyMethods( array( 'fromArray' ) )
127
			->getMock();
128
129
		$object->expects( $this->once() )->method( 'fromArray' )
130
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
131
132
		$this->view = \TestHelper::view();
133
		$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create();
134
135
		$object->setView( $this->view );
136
137
		$this->expectException( \Aimeos\MShop\Exception::class );
138
		$object->save();
139
	}
140
141
142
	public function testGetSubClient()
143
	{
144
		$this->expectException( \LogicException::class );
145
		$this->object->getSubClient( 'unknown' );
146
	}
147
}
148