| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Aimeos (aimeos.org), 2018 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Aimeos\MShop\Customer\Manager\Property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class Typo3Test extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $editor = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$context = \TestHelper::getContext(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->editor = $context->getEditor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $context, 'Typo3' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$this->object = $manager->getSubManager( 'property', 'Typo3' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 	protected function tearDown() : void | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 		unset( $this->object ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	public function testClear() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( array( -1 ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	public function testCreateItem() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$item = $this->object->createItem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Property\\Iface', $item ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	public function testSaveUpdateDeleteItem() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$search = $this->object->createSearch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$search->setConditions( $search->compare( '==', 'customer.property.editor', $this->editor ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		$results = $this->object->searchItems( $search ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		if( ( $item = reset( $results ) ) === false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			throw new \RuntimeException( 'No property item found' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$item->setId( null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$item->setLanguageId( 'en' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$resultSaved = $this->object->saveItem( $item ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$itemSaved = $this->object->getItem( $item->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		$itemExp = clone $itemSaved; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$itemExp->setValue( 'unittest' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$resultUpd = $this->object->saveItem( $itemExp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$itemUpd = $this->object->getItem( $itemExp->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->object->deleteItem( $itemSaved->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$context = \TestHelper::getContext(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$this->assertTrue( $item->getId() !== null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$this->assertEquals( $item->getId(), $itemSaved->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$this->assertEquals( $item->getType(), $itemSaved->getType() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$this->assertEquals( $item->getValue(), $itemSaved->getValue() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		$this->expectException( '\\Aimeos\\MShop\\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$this->object->getItem( $itemSaved->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	public function testGetItem() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$search = $this->object->createSearch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$conditions = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			$search->compare( '~=', 'customer.property.value', '1' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			$search->compare( '==', 'customer.property.editor', $this->editor ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$search->setConditions( $search->combine( '&&', $conditions ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		$results = $this->object->searchItems( $search ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		if( ( $expected = reset( $results ) ) === false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 			throw new \RuntimeException( sprintf( 'No customer property item found for value "%1$s".', '1' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		$actual = $this->object->getItem( $expected->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		$this->assertEquals( $expected, $actual ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	public function testGetResourceType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		$result = $this->object->getResourceType(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$this->assertContains( 'customer/property', $result ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	public function testGetSearchAttributes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		foreach( $this->object->getSearchAttributes() as $attribute ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	public function testSearchItems() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		$total = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		$search = $this->object->createSearch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		$expr = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 		$expr[] = $search->compare( '!=', 'customer.property.id', null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		$expr[] = $search->compare( '!=', 'customer.property.parentid', null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		$expr[] = $search->compare( '!=', 'customer.property.siteid', null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		$expr[] = $search->compare( '==', 'customer.property.type', 'newsletter' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		$expr[] = $search->compare( '==', 'customer.property.languageid', null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		$expr[] = $search->compare( '==', 'customer.property.value', '1' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		$expr[] = $search->compare( '==', 'customer.property.editor', $this->editor ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		$search->setConditions( $search->combine( '&&', $expr ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		$results = $this->object->searchItems( $search, [], $total ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		$this->assertEquals( 1, count( $results ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	public function testGetSubManager() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Standard' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		$this->expectException( '\\Aimeos\\MShop\\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		$this->object->getSubManager( 'unknown' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 	public function testGetSubManagerInvalidName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 		$this->expectException( '\\Aimeos\\MShop\\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 		$this->object->getSubManager( 'type', 'unknown' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 172 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 173 |  |  |  |