| 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\Stock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class StandardTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$this->context = \TestHelper::context(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->object = new \Aimeos\Controller\Frontend\Stock\Standard( $this->context ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	protected function tearDown() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		unset( $this->object, $this->context ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	public function testProduct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		$item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$this->assertEquals( 1, count( $this->object->product( $item->getId() )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	public function testCompare() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		$this->assertEquals( 7, count( $this->object->compare( '==', 'stock.stocklevel', null )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	public function testGet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$manager = \Aimeos\MShop::create( $this->context, 'stock' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$item = $manager->search( $manager->filter()->slice( 0, 1 ), ['stock/type'] )->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$exp = $this->object->uses( ['stock/type'] )->get( $item->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Stock\Item\Iface::class, $exp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Type\Item\Iface::class, $exp->getTypeItem() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	public function testParse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$cond = ['||' => [['==' => ['stock.dateback' => null]], ['>=' => ['stock.dateback' => '2010-01-01 00:00:00']]]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$this->assertEquals( 19, count( $this->object->parse( $cond )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	public function testSearch() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$total = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->assertGreaterThanOrEqual( 15, count( $this->object->uses( ['stock/type'] )->search( $total ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->assertGreaterThanOrEqual( 15, $total ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	public function testSlice() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	public function testSort() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$this->assertGreaterThanOrEqual( 15, count( $this->object->sort()->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	public function testSortGeneric() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		$this->assertGreaterThanOrEqual( 15, count( $this->object->sort( 'stock.dateback' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	public function testSortMultiple() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$this->assertGreaterThanOrEqual( 15, count( $this->object->sort( 'stock.type,-stock.dateback' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	public function testSortStock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		$result = $this->object->sort( 'stock' )->search(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$this->assertStringStartsWith( 100, $result->first()->getStocklevel() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 	public function testSortStockDesc() | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 		$result = $this->object->sort( '-stock' )->search(); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 		$this->assertStringStartsWith( 100, $result->last()->getStocklevel() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	public function testType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$this->assertEquals( 8, count( $this->object->type( 'default' )->search() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |  |