| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Aimeos (aimeos.org), 2017-2025 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Aimeos\Controller\Frontend\Attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class StandardTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$this->context = \TestHelper::context(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->object = new \Aimeos\Controller\Frontend\Attribute\Standard( $this->context ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	protected function tearDown() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		unset( $this->object, $this->context ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	public function testAttribute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		$manager = \Aimeos\MShop::create( $this->context, 'attribute' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		$blueId = $manager->find( 'blue', [], 'product', 'color' )->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$whiteId = $manager->find( 'white', [], 'product', 'color' )->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		$this->assertEquals( 2, count( $this->object->attribute( [$blueId, $whiteId] )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	public function testDomain() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$this->assertEquals( 5, count( $this->object->domain( 'media' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	public function testCompare() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$this->assertEquals( 5, count( $this->object->compare( '==', 'attribute.type', 'color' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	public function testFind() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$item = $this->object->uses( ['text'] )->find( 'white', 'color' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Attribute\Item\Iface::class, $item ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 	public function testFunction() | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 		$str = $this->object->function( 'attribute:prop', ['type', null, 'value'] ); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 		$this->assertEquals( 'attribute:prop("type",null,"value")', $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	public function testGet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->find( 'white', [], 'product', 'color' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$item = $this->object->uses( ['text'] )->get( $item->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Attribute\Item\Iface::class, $item ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	public function testHas() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$this->assertEquals( 3, count( $this->object->has( 'price', 'default' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	public function testParse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$cond = ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$this->assertEquals( 5, count( $this->object->parse( $cond )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	public function testProperty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$this->assertEquals( 1, count( $this->object->property( 'size', '1024' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	public function testSearch() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		$total = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$items = $this->object->uses( ['text'] )->sort( 'attribute.code' )->search( $total ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$this->assertGreaterThanOrEqual( 26, count( $items ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$this->assertGreaterThanOrEqual( 26, $total ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$this->assertEquals( 1, count( $items->last()->getRefItems( 'text' ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public function testSlice() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	public function testSort() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort()->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	public function testSortGeneric() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort( 'attribute.status' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	public function testSortMultiple() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort( 'attribute.status,-attribute.code' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	public function testSortPosition() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		$result = $this->object->sort( 'position' )->search(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		$this->assertEquals( 'white', $result->first()->getCode() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	public function testSortCodeDesc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		$result = $this->object->sort( '-position' )->search(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		$this->assertStringStartsWith( 'white', $result->last()->getCode() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	public function testType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		$this->assertEquals( 6, count( $this->object->type( 'size' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	public function testUses() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 		$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 159 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 160 |  |  |  |