Passed
Push — master ( 8bcf0d...10ee87 )
by Aimeos
06:29
created

DownloadTest::testIsAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020
6
 */
7
8
9
namespace Aimeos\MShop\Service\Provider\Decorator;
10
11
12
class DownloadTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $servItem;
17
	private $mockProvider;
18
19
20
	protected function setUp() : void
21
	{
22
		$this->context = \TestHelperMShop::getContext();
23
24
		$servManager = \Aimeos\MShop\Service\Manager\Factory::create( $this->context );
25
		$this->servItem = $servManager->createItem();
26
27
		$this->mockProvider = $this->getMockBuilder( \Aimeos\MShop\Service\Provider\Decorator\Example::class )
28
			->disableOriginalConstructor()->getMock();
29
30
		$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Free( $this->mockProvider, $this->context, $this->servItem );
31
	}
32
33
34
	protected function tearDown() : void
35
	{
36
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\Aimeos\MShop\Order\Manager\StandardMock', null );
37
	}
38
39
40
	public function testGetConfigBE()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
41
	{
42
		$this->mockProvider->expects( $this->once() )->method( 'getConfigBE' )->will( $this->returnValue( [] ) );
43
44
		$result = $this->object->getConfigBE();
45
46
		$this->assertArrayHasKey( 'free.show', $result );
47
	}
48
49
50
	public function testCheckConfigBEOK()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
51
	{
52
		$this->mockProvider->expects( $this->once() )
53
			->method( 'checkConfigBE' )
54
			->will( $this->returnValue( [] ) );
55
56
		$attributes = array( 'free.show' => '1' );
57
		$result = $this->object->checkConfigBE( $attributes );
58
59
		$this->assertEquals( 1, count( $result ) );
60
		$this->assertNull( $result['free.show'] );
61
	}
62
63
64
	public function testCheckConfigBEFailure()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
65
	{
66
		$this->mockProvider->expects( $this->once() )
67
			->method( 'checkConfigBE' )
68
			->will( $this->returnValue( [] ) );
69
70
		$attributes = array( 'free.show' => [] );
71
		$result = $this->object->checkConfigBE( $attributes );
72
73
		$this->assertEquals( 1, count( $result ) );
74
		$this->assertIsString( $result['free.show'] );
75
	}
76
77
78
	public function testIsAvailable()
79
	{
80
		$this->servItem->setConfig( array( 'free.show' => '1' ) );
81
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->off();
82
83
		$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) );
84
85
		$this->assertTrue( $this->object->isAvailable( $basket ) );
86
	}
87
88
89
	public function testIsNotAvailable()
90
	{
91
		$this->servItem->setConfig( array( 'free.show' => '1' ) );
92
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->off()->getPrice()->setValue( '0.01' );
93
94
		$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) );
95
96
		$this->assertFalse( $this->object->isAvailable( $basket ) );
97
	}
98
99
100
	public function testIsAvailableHidden()
101
	{
102
		$this->servItem->setConfig( array( 'free.show' => '0' ) );
103
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->off()->getPrice()->setValue( '0.01' );
104
105
		$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) );
106
107
		$this->assertTrue( $this->object->isAvailable( $basket ) );
108
	}
109
110
111
	public function testIsNotAvailableHidden()
112
	{
113
		$this->servItem->setConfig( array( 'free.show' => '0' ) );
114
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->off();
115
116
		$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) );
117
118
		$this->assertFalse( $this->object->isAvailable( $basket ) );
119
	}
120
}
121