Exemple #1
0
 private function prepareCloseByOwner()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $location1 = new Location();
     $location1->setName('Location name');
     $location1->setCity('Location city');
     $location1->setStreet('Location street');
     $location1->setNumber('Location number');
     $location1->setApartment('Location apartment');
     $location1->setPostal('00-000');
     $location1->setPhone('+48100000000');
     $location1->setEmail('*****@*****.**');
     $this->persist($location1);
     $location2 = new Location();
     $location2->setName('Location name 2');
     $location2->setCity('Location city');
     $location2->setStreet('Location street');
     $location2->setNumber('Location number');
     $location2->setApartment('Location apartment');
     $location2->setPostal('00-000');
     $location2->setPhone('+48100000000');
     $location2->setEmail('*****@*****.**');
     $this->persist($location2);
     $role = new Role();
     $role->setName('Admin');
     foreach ($em->getRepository('Entity\\Functionality')->findAll() as $functionality) {
         $role->getFunctionalities()->add($functionality);
     }
     $this->persist($role);
     $owner = new User();
     $owner->setEmail('*****@*****.**');
     $owner->setFirstName('first name');
     $owner->setLastName('last name');
     $owner->setLocation($location2);
     $owner->setRole($role);
     $this->persist($owner);
     $performer = new User();
     $performer->setEmail('*****@*****.**');
     $performer->setFirstName('first name');
     $performer->setLastName('last name');
     $performer->setLocation($location1);
     $performer->setRole($role);
     $this->persist($performer);
     $deviceTag = new DeviceTag();
     $deviceTag->setName('DeviceTag name');
     $this->persist($deviceTag);
     $device = new Device();
     $device->setName('Device name');
     $device->setPhoto('Device.photo.jpg');
     $device->getTags()->add($deviceTag);
     $device->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $device->setState($em->getRepository('Entity\\DeviceState')->findOneById(1));
     $device->setSerialNumber('Device serial number');
     $device->setState($em->getRepository('Entity\\DeviceState')->findOneById(2));
     $device->setSymbol('?');
     $device->setLocation($location1);
     $device->setUser($performer);
     $this->persist($device);
     $order = new Order();
     $order->setOwner($owner);
     $order->setState($em->getRepository('Entity\\OrderState')->findOneById(2));
     $order->setDevice($device);
     $order->setPerformer($performer);
     $order->setFetchedAt(new \DateTime());
     $this->persist($order);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $owner->getId());
     $client = $this->createClient($session);
     $client->loadPage('/order/show/' . $order->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Invalid status code.');
     $timeLines = $client->findElements('.timeline-entry');
     $this->assertCount(2, $timeLines, 'Invalid number steps');
     $buttons = $timeLines[1]->findElements('a');
     $this->assertCount(2, $buttons, 'Invalid buttons number');
     $this->assertEquals('Me', $buttons[0]->getHtml(), 'Invalid Me label');
     $this->assertEquals('My location', $buttons[1]->getHtml(), 'Invalid Location label');
     return array($buttons, $order, $performer, $device, $location2, $client, $owner);
 }
 public function testFreeRemove()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $deviceTag = new DeviceTag();
     $deviceTag->setName('DeviceTag name');
     $this->persist($deviceTag);
     $device = new Device();
     $device->setName('Device name');
     $device->setPhoto('Device.photo.jpg');
     $device->getTags()->add($deviceTag);
     $device->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $device->setSerialNumber('Device serial number');
     $device->setState($em->getRepository('Entity\\DeviceState')->findOneById(2));
     $device->setUser($this->user);
     $device->setLocation($this->user->getLocation());
     $device->setSymbol('REF1');
     $this->persist($device);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $this->user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/device/location/free/' . $device->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Invalid status code.');
     $panelBody = $client->getElement('.panel-body');
     $buttons = $panelBody->findElements('a');
     $this->assertCount(2, $buttons, 'Invalid number buttons');
     $this->assertEquals('Yes', $buttons[0]->getText(), 'Invalid text button YES');
     $this->assertEquals('No', $buttons[1]->getText(), 'Invalid text button NO');
     $buttons[1]->click();
     $this->assertEquals('/device/location', $client->getUrl(), 'Invalid url button NO.');
     $buttons[0]->click();
     $this->assertEquals('/device/location', $client->getUrl(), 'Invalid url button YES.');
     $em->clear();
     $device = $em->getRepository('Entity\\Device')->findOneBy(array('id' => $device->getId()));
     $this->assertEquals(1, $device->getState()->getId(), 'Invalid device state.');
 }
 /**
  * Assign device to me
  *
  * @param \Entity\Device $entity
  * @return Response
  */
 public function assign($entity)
 {
     if ($entity->getLocation()->getId() != $this->getUser()->getId()) {
         throw new DeviceNotFoundException();
     }
     if ($entity->getUser()) {
         throw new AlreadyHasOwnerException();
     }
     $entity->setUser($this->getUser());
     $this->flush();
     $response = new Response();
     $response->redirect('/device/location');
     return $response;
 }
Exemple #4
0
 /**
  * Assign device to my location
  *
  * @param \Entity\Device $entity
  * @return Response
  */
 public function assign($entity)
 {
     if ($entity->getUser()->getId() != $this->getUser()->getId()) {
         throw new YouAreNotOwnerException();
     }
     $entity->setUser(null);
     $this->flush();
     $response = new Response();
     $response->redirect('/device/my');
     return $response;
 }