public function testMapObject()
 {
     $mapping = $this->mapper->mapObject($this->product);
     $this->assertEquals('test product ', $mapping['text']['name']);
     $this->assertEquals(150, $mapping['decimal']['price']);
     $this->assertEquals(10, $mapping['integer']['count']);
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $this->mapper->mapObject($manufacturer);
 }
Esempio n. 2
0
 public function testMapObject()
 {
     $productName = $this->product->getName();
     $productDescription = $this->product->getDescription();
     $manufacturerName = $this->product->getManufacturer()->getName();
     $allTextData = sprintf('%s %s %s', $productName, $productDescription, $manufacturerName);
     $productMapping = array('text' => array('name' => $productName, 'description' => $productDescription, 'manufacturer' => $manufacturerName, 'all_data' => $allTextData, Indexer::TEXT_ALL_DATA_FIELD => $allTextData), 'decimal' => array('price' => $this->product->getPrice()), 'integer' => array('count' => $this->product->getCount()));
     $this->assertEquals($productMapping, $this->mapper->mapObject($this->product));
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $manufacturerMapping = array('text' => array('products' => $productName, Indexer::TEXT_ALL_DATA_FIELD => $productName));
     $this->assertEquals($manufacturerMapping, $this->mapper->mapObject($manufacturer));
 }
Esempio n. 3
0
 /**
  * Tests the following features:
  * * many-to-many relation
  * * nested many-to-many relation
  * * nested many-to-many relation without 'target_fields' mappings
  */
 public function testMapObjectForCategory()
 {
     $categoryName = $this->category->getName();
     $productName = $this->product->getName();
     $manufacturerName = $this->manufacturer->getName();
     $expectedMapping = ['text' => ['name' => $categoryName, 'products' => $productName, 'manufacturers' => $manufacturerName, Indexer::TEXT_ALL_DATA_FIELD => $categoryName . ' ' . $productName . ' ' . $manufacturerName]];
     $this->assertEquals($expectedMapping, $this->mapper->mapObject($this->category));
 }
Esempio n. 4
0
 public function testSave()
 {
     $query = $this->getMock('Doctrine\\ORM\\AbstractQuery', array('getSQL', 'setMaxResults', 'getOneOrNullResult', 'setParameter', '_doExecute'), array(), '', false);
     $this->mapper->expects($this->any())->method('mapObject')->will($this->returnValue(array(array())));
     $this->om->expects($this->once())->method('createQuery')->will($this->returnValue($query));
     $query->expects($this->any())->method('setParameter')->will($this->returnValue($query));
     $query->expects($this->once())->method('setMaxResults')->will($this->returnValue($query));
     $query->expects($this->once())->method('getOneOrNullResult')->will($this->returnValue(0));
     $searchRepo = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Entity\\Repository\\SearchIndexRepository')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getRepository')->with($this->equalTo('OroSearchBundle:Item'))->will($this->returnValue($searchRepo));
     $this->container->expects($this->any())->method('getParameter')->with($this->equalTo('oro_search.engine_orm'))->will($this->returnValue('test_orm'));
     $searchRepo->expects($this->any())->method('setDriversClasses');
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $reflectionProperty = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock();
     $meta->expects($this->any())->method('getReflectionProperty')->will($this->returnValue($reflectionProperty));
     $this->om->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $meta->expects($this->any())->method('getSingleIdentifierFieldName')->will($this->returnValue('id'));
     $reflectionProperty->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($uow));
     $uow->expects($this->any())->method('computeFields');
     $this->orm->save($this->product, true, true);
     $this->orm->save($this->product, false);
     $this->mapper->expects($this->once())->method('getEntityConfig')->will($this->returnValue(array('alias' => 'test')));
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $this->orm->save($manufacturer, true);
 }