コード例 #1
0
 /**
  * @param Customer $entity
  * @return array
  */
 protected function buildTreeRecursive(Customer $entity)
 {
     $entities = [];
     $children = $entity->getChildren();
     foreach ($children->toArray() as $child) {
         $entities[] = $child;
         $entities = array_merge($entities, $this->buildTreeRecursive($child));
     }
     return $entities;
 }
コード例 #2
0
 /**
  * @param ObjectManager $manager
  * @param string $name
  * @param Customer $parent
  * @return Customer
  */
 protected function createCustomer(ObjectManager $manager, $name, Customer $parent = null)
 {
     $customer = new Customer();
     $customer->setName($name);
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $customer->setOrganization($organization);
     if ($parent) {
         $customer->setParent($parent);
     }
     $manager->persist($customer);
     $this->addReference($name, $customer);
     return $customer;
 }
 /**
  * @dataProvider postSubmitDataProvider
  */
 public function testPostSubmit(array $allAddresses, $formAddressKey, array $expectedAddressesData)
 {
     // Set owner for all addresses
     $customer = new Customer();
     foreach ($allAddresses as $address) {
         $customer->addAddress($address);
     }
     $event = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->setMethods(['getData'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getData')->will($this->returnValue($allAddresses[$formAddressKey]));
     $this->subscriber->postSubmit($event);
     foreach ($expectedAddressesData as $addressKey => $expectedData) {
         /** @var CustomerAddress $address */
         $address = $allAddresses[$addressKey];
         $defaultTypeNames = [];
         /** @var AddressType $defaultType */
         foreach ($address->getDefaults() as $defaultType) {
             $defaultTypeNames[] = $defaultType->getName();
         }
         $this->assertEquals($expectedData['defaults'], $defaultTypeNames);
     }
 }
コード例 #4
0
 /**
  * @param Customer $customer
  * @param CustomerAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Customer $customer, CustomerAddress $address)
 {
     $responseData = ['saved' => false, 'customer' => $customer];
     if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) {
         if (!$customer->getAddresses()->count()) {
             $address->setPrimary(true);
         }
     }
     if ($address->getOwner() && $address->getOwner()->getId() != $customer->getId()) {
         throw new BadRequestHttpException('Address must belong to customer');
     } elseif (!$address->getOwner()) {
         $customer->addAddress($address);
     }
     $form = $this->createForm(CustomerTypedAddressType::NAME, $address);
     $handler = new AddressHandler($form, $this->getRequest(), $this->getDoctrine()->getManagerForClass('OroB2BCustomerBundle:CustomerAddress'));
     if ($handler->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $form->createView();
     return $responseData;
 }
コード例 #5
0
 public function testProcessValidData()
 {
     $appendedCustomer = new Customer();
     $removedCustomer = new Customer();
     $removedCustomer->setGroup($this->entity);
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $appendForm->expects($this->once())->method('getData')->will($this->returnValue([$appendedCustomer]));
     $this->form->expects($this->at(3))->method('get')->with('appendCustomers')->will($this->returnValue($appendForm));
     $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $removeForm->expects($this->once())->method('getData')->will($this->returnValue([$removedCustomer]));
     $this->form->expects($this->at(4))->method('get')->with('removeCustomers')->will($this->returnValue($removeForm));
     $this->manager->expects($this->at(0))->method('persist')->with($appendedCustomer);
     $this->manager->expects($this->at(1))->method('persist')->with($removedCustomer);
     $this->manager->expects($this->at(2))->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $this->assertEquals($this->entity, $appendedCustomer->getGroup());
     $this->assertNull($removedCustomer->getGroup());
 }
コード例 #6
0
 /**
  * @Route("/info/{id}", name="orob2b_customer_info", requirements={"id"="\d+"})
  * @Template("OroB2BCustomerBundle:Customer/widget:info.html.twig")
  * @AclAncestor("orob2b_customer_view")
  *
  * @param Customer $customer
  * @return array
  */
 public function infoAction(Customer $customer)
 {
     return ['entity' => $customer, 'treeData' => $this->get('orob2b_customer.customer_tree_handler')->createTree($customer->getId())];
 }
コード例 #7
0
 /**
  * @return array
  */
 public function submitWithFormSubscribersProvider()
 {
     $customerAddress1 = new CustomerAddress();
     $customerAddress1->setTypes(new ArrayCollection([$this->billingType, $this->shippingType]));
     $customerAddress2 = new CustomerAddress();
     $customerAddress2->setTypes(new ArrayCollection([$this->billingType, $this->shippingType]))->setDefaults(new ArrayCollection([$this->billingType, $this->shippingType]));
     $customerAddressExpected = new CustomerAddress();
     $customerAddressExpected->setPrimary(true)->addType($this->billingType)->addType($this->shippingType)->removeType($this->billingType)->removeType($this->shippingType)->addType($this->billingType)->addType($this->shippingType)->setDefaults(new ArrayCollection([$this->billingType, $this->shippingType]));
     $customer = new Customer();
     $customer->addAddress($customerAddress1);
     $customer->addAddress($customerAddress2);
     return ['FixCustomerAddressesDefaultSubscriber check' => ['options' => [], 'defaultData' => $customerAddress1, 'viewData' => $customerAddress1, 'submittedData' => ['types' => [AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING], 'defaults' => ['default' => [AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING]], 'primary' => true], 'expectedData' => $customerAddressExpected, 'otherAddresses' => [$customerAddress2], 'updateOwner' => $customer]];
 }
コード例 #8
0
 /**
  * @ORM\PrePersist
  */
 public function createCustomer()
 {
     if (!$this->customer) {
         $this->customer = new Customer();
         $this->customer->setOrganization($this->organization);
         $this->customer->setName(sprintf('%s %s', $this->firstName, $this->lastName));
     }
 }
コード例 #9
0
 /**
  * @param string $html
  * @param string $name
  * @param Customer $parent
  * @param CustomerGroup $group
  */
 protected function assertViewPage($html, $name, Customer $parent, CustomerGroup $group, AbstractEnumValue $internalRating)
 {
     $this->assertContains($name, $html);
     $this->assertContains($parent->getName(), $html);
     $this->assertContains($group->getName(), $html);
     $this->assertContains($internalRating->getName(), $html);
 }
コード例 #10
0
 public function testCustomerView()
 {
     $this->client->request('GET', $this->getUrl('orob2b_customer_view', ['id' => $this->customer->getId()]));
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
 }