| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Aimeos (aimeos.org), 2017-2023 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Aimeos\Controller\Frontend\Attribute\Decorator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class BaseTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	private $stub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->context = \TestHelper::context(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Standard::class ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 			->setConstructorArgs( [$this->stub, $this->context] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 			->getMockForAbstractClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	protected function tearDown() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		unset( $this->context, $this->object, $this->stub ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	public function testCall() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Standard::class ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			->onlyMethods( ['__call'] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			->setConstructorArgs( [$stub, $this->context] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			->getMockForAbstractClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$this->assertTrue( $object->invalid() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	public function testAttribute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$this->assertSame( $this->object, $this->object->attribute( [1, 3] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	public function testDomain() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$this->assertSame( $this->object, $this->object->domain( 'catalog' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	public function testCompare() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->assertSame( $this->object, $this->object->compare( '==', 'attribute.code', 'test' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	public function testFind() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$expected = \Aimeos\MShop\Attribute\Item\Iface::class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$this->stub->expects( $this->once() )->method( 'find' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			->will( $this->returnValue( $item ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$this->assertInstanceOf( $expected, $this->object->find( 'test', 'color' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	public function testFunction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$this->stub->expects( $this->once() )->method( 'function' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			->will( $this->returnValue( 'attribute:prop("type",null,"value")' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$str = $this->object->function( 'attribute:prop', ['type', null, 'value'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$this->assertEquals( 'attribute:prop("type",null,"value")', $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	public function testGet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		$expected = \Aimeos\MShop\Attribute\Item\Iface::class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$this->stub->expects( $this->once() )->method( 'get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			->will( $this->returnValue( $item ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$this->assertInstanceOf( $expected, $this->object->get( 1 ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	public function testHas() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		$this->assertSame( $this->object, $this->object->has( 'price', 'default', -1 ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 	public function testParse() | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		$this->assertSame( $this->object, $this->object->parse( [] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	public function testProperty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	public function testSearch() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 		$expected = \Aimeos\MShop\Attribute\Item\Iface::class; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		$total = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		$this->stub->expects( $this->once() )->method( 'search' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 			->will( $this->returnValue( map( [$item] ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		$this->assertEquals( [$item], $this->object->search( $total )->toArray() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	public function testSlice() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	public function testSort() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		$this->assertSame( $this->object, $this->object->sort( 'position' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	public function testUses() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	public function testGetController() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		$this->assertSame( $this->stub, $result ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	protected function access( $name ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		$method = $class->getMethod( $name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 		$method->setAccessible( true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 		return $method; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 173 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 174 |  |  |  |