StandardTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Supplier\Media\Property;
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\Supplier\Media\Property\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, 'supplier' );
40
41
		$this->view->item = $manager->create();
42
		$result = $this->object->create();
43
44
		$this->assertStringContainsString( 'Media properties', $result );
45
		$this->assertEmpty( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
52
53
		$this->view->item = $manager->find( 'unitSupplier001', ['media'] );
54
		$result = $this->object->copy();
55
56
		$this->assertEmpty( $this->view->get( 'errors' ) );
57
		$this->assertStringContainsString( 'Media properties', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertEmpty( $this->view->get( 'errors' ) );
66
		$this->assertEmpty( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
73
74
		$this->view->item = $manager->find( 'unitSupplier001', ['media'] );
75
		$result = $this->object->get();
76
77
		$this->assertEmpty( $this->view->get( 'errors' ) );
78
		$this->assertStringContainsString( 'Media properties', $result );
79
	}
80
81
82
	public function testSave()
83
	{
84
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
85
86
		$item = $manager->find( 'unitSupplier001', ['media'] );
87
		$item->setCode( 'jqadm-test-media-property' );
88
		$item->setId( null );
89
90
		$this->view->item = $manager->save( $item );
91
92
		$param = array(
93
			'site' => 'unittest',
94
			'media' => array(
95
				0 => array(
96
					'property' => array(
97
						0 => array(
98
							'media.property.id' => '',
99
							'media.property.type' => 'size',
100
						),
101
					),
102
				),
103
			),
104
		);
105
106
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
107
		$this->view->addHelper( 'param', $helper );
108
109
110
		$result = $this->object->save();
111
112
113
		$manager->delete( $this->view->item->getId() );
114
115
		$this->assertEmpty( $this->view->get( 'errors' ) );
116
		$this->assertEmpty( $result );
117
118
		$mediaItems = $this->view->item->getRefItems( 'media' )->toArray();
119
		$this->assertEquals( 1, count( $mediaItems ) );
120
		$this->assertEquals( 1, count( reset( $mediaItems )->getPropertyItems() ) );
121
	}
122
123
124
	public function testSaveException()
125
	{
126
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Supplier\Media\Property\Standard::class )
127
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
128
			->onlyMethods( array( 'fromArray' ) )
129
			->getMock();
130
131
		$object->expects( $this->once() )->method( 'fromArray' )
132
			->will( $this->throwException( new \RuntimeException() ) );
133
134
		$this->view = \TestHelper::view();
135
		$this->view->item = \Aimeos\MShop::create( $this->context, 'supplier' )->create();
136
137
		$object->setView( $this->view );
138
139
		$this->expectException( \RuntimeException::class );
140
		$object->save();
141
	}
142
143
144
	public function testSearch()
145
	{
146
		$this->assertEmpty( $this->object->search() );
147
	}
148
149
150
	public function testGetSubClient()
151
	{
152
		$this->expectException( \LogicException::class );
153
		$this->object->getSubClient( 'unknown' );
154
	}
155
}
156