Exemplo n.º 1
0
 /**
  * Configure enviorment.
  */
 protected function setUp()
 {
     $this->executeCommand('migrate:downgrade');
     $this->executeCommand('migrate:update');
     $em = $this->getService('doctrine')->getEntityManager();
     $this->log = new \Entity\Log();
     $this->log->setAction($this->getService('doctrine')->getRepository('Entity\\LogAction')->findOneById(14));
     $this->log->setIpAddress('127.0.0.1');
     $this->log->setIsSuccess(true);
     $this->log->setCountModifiedEntities(0);
     $em->persist($this->log);
     $role = new Role();
     $role->setName('Admin');
     foreach ($em->getRepository('Entity\\Functionality')->findAll() as $functionality) {
         $role->getFunctionalities()->add($functionality);
     }
     $this->persist($role);
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('first name');
     $user->setLastName('last name');
     $user->setLocation($em->getRepository('Entity\\Location')->findOneBy(array()));
     $user->setRole($role);
     $em->persist($user);
     $this->createLogEntity($user);
     $em->flush();
     $this->user = $user;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public function testEdit()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $location = $em->getRepository('Entity\\Location')->findOneBy(array());
     $em->remove($location);
     $location = new Location();
     $location->setName('Location name');
     $location->setCity('Location city');
     $location->setStreet('Location street');
     $location->setNumber('Location number');
     $location->setApartment('Location apartment');
     $location->setPostal('00-000');
     $location->setPhone('+48100000000');
     $location->setEmail('*****@*****.**');
     $this->persist($location);
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('first name');
     $user->setLastName('last name');
     $user->setLocation($location);
     $this->persist($user);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/location/edit/' . $location->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Invalid status code.');
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertCount(8, $fields, 'Invalid number fields');
     $this->assertEquals('Location name', $fields[0]->getData(), 'Invalid field value for name');
     $this->assertEquals('Location city', $fields[1]->getData(), 'Invalid field value for city');
     $this->assertEquals('Location street', $fields[2]->getData(), 'Invalid field value for street');
     $this->assertEquals('Location number', $fields[3]->getData(), 'Invalid field value for number');
     $this->assertEquals('Location apartment', $fields[4]->getData(), 'Invalid field value for number');
     $this->assertEquals('00-000', $fields[5]->getData(), 'Invalid field value for number');
     $this->assertEquals('+48100000000', $fields[6]->getData(), 'Invalid field value for number');
     $this->assertEquals('*****@*****.**', $fields[7]->getData(), 'Invalid field value for number');
     $fields[0]->setData('');
     $fields[1]->setData('');
     $fields[2]->setData('');
     $fields[3]->setData('');
     $fields[4]->setData('');
     $fields[5]->setData('');
     $fields[6]->setData('');
     $fields[7]->setData('');
     $form->submit();
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertEquals('/location/edit/' . $location->getId(), $client->getUrl(), 'Invalid url form after submited location');
     $this->assertCount(8, $fields, 'Invalid number fields');
     $this->assertEquals('Value can not empty', $fields[0]->getParent()->getElement('label')->getText(), 'Invalid error message for name');
     $this->assertEquals('Value can not empty', $fields[1]->getParent()->getElement('label')->getText(), 'Invalid error message for city');
     $this->assertEquals('Value can not empty', $fields[2]->getParent()->getElement('label')->getText(), 'Invalid error message for street');
     $this->assertEquals('Value can not empty', $fields[3]->getParent()->getElement('label')->getText(), 'Invalid error message for number');
     $this->assertFalse($fields[4]->getParent()->hasElement('label'), 'Redundant error message for apartment');
     $this->assertEquals('Value can not empty', $fields[5]->getParent()->getElement('label')->getText(), 'Invalid error message for postal');
     $this->assertEquals('Value can not empty', $fields[6]->getParent()->getElement('label')->getText(), 'Invalid error message for phone');
     $this->assertEquals('Invalid email format.', $fields[7]->getParent()->getElement('label')->getText(), 'Invalid error message for email');
     $fields[0]->setData('name edit');
     $fields[1]->setData('city edit');
     $fields[2]->setData('street edit');
     $fields[3]->setData('number edit');
     $fields[4]->setData('apartment edit');
     $fields[5]->setData('12-123');
     $fields[6]->setData('+48123123123');
     $fields[7]->setData('*****@*****.**');
     $form->submit();
     $this->assertEquals('/location', $client->getUrl(), 'Invalid url form after submited location');
     $em->clear();
     $locations = $em->getRepository('Entity\\Location')->findAll();
     $this->assertCount(1, $locations, 'Invalid number locations');
     $location = $locations[0];
     $this->assertEquals('name edit', $location->getName(), 'Invalid location name');
     $this->assertEquals('city edit', $location->getCity(), 'Invalid location city');
     $this->assertEquals('street edit', $location->getStreet(), 'Invalid location street');
     $this->assertEquals('number edit', $location->getNumber(), 'Invalid location number');
     $this->assertEquals('apartment edit', $location->getApartment(), 'Invalid location apartment');
     $this->assertEquals('12-123', $location->getPostal(), 'Invalid location postal');
     $this->assertEquals('+48123123123', $location->getPhone(), 'Invalid location phone');
     $this->assertEquals('*****@*****.**', $location->getEmail(), 'Invalid location email');
 }
Exemplo n.º 4
0
 public function testRemove()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $location = new Location();
     $location->setName('Location name');
     $location->setCity('Location city');
     $location->setStreet('Location street');
     $location->setNumber('Location number');
     $location->setApartment('Location apartment');
     $location->setPostal('00-000');
     $location->setPhone('+48100000000');
     $location->setEmail('*****@*****.**');
     $this->persist($location);
     $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(1));
     $device->setLocation($location);
     $device->setSymbol('REF1');
     $this->persist($device);
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('first name');
     $user->setLastName('last name');
     $user->setLocation($location);
     $this->persist($user);
     $order = new Order();
     $order->setOwner($user);
     $order->setState($em->getRepository('Entity\\OrderState')->findOneById(1));
     $order->setDevice($device);
     $this->persist($order);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $this->user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/device/remove/' . $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', $client->getUrl(), 'Invalid url button NO.');
     $buttons[0]->click();
     $this->assertEquals('/device', $client->getUrl(), 'Invalid url button YES.');
     //check removed in database
     $this->assertCount(0, $em->getRepository('Entity\\Device')->findAll());
 }
Exemplo n.º 5
0
 /**
  * Setting entity from form data
  *
  * @param \Entity\User $entity
  * @param $data
  */
 private function setEntity($entity, $data)
 {
     $entity->setFirstName($data['firstName']);
     $entity->setLastName($data['lastName']);
     $entity->setLocation($this->cast('Mapper\\Location', $data['location']));
     $entity->setRole($this->cast('Mapper\\Role', $data['role']));
     $this->persist($entity);
 }
Exemplo n.º 6
0
 public function testEdit()
 {
     $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 2 name');
     $location2->setCity('Location 2 city');
     $location2->setStreet('Location 2 street');
     $location2->setNumber('Location 2 number');
     $location2->setApartment('Location 2 apartment');
     $location2->setPostal('02-000');
     $location2->setPhone('+28100000000');
     $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);
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('first name');
     $user->setLastName('last name');
     $user->setLocation($location1);
     $user->setRole($role);
     $this->persist($user);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/user/edit/' . $user->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Invalid status code.');
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertCount(5, $fields, 'Invalid number fields');
     $this->assertEquals('*****@*****.**', $fields[0]->getData(), 'Invalid field value for email');
     $this->assertEquals('first name', $fields[1]->getData(), 'Invalid field value for first name');
     $this->assertEquals('last name', $fields[2]->getData(), 'Invalid field value for last name');
     $this->assertEquals($location1->getId(), $fields[3]->getData(), 'Invalid field value for location');
     $fields[0]->setData('');
     $fields[1]->setData('');
     $fields[2]->setData('');
     $fields[3]->setData('');
     $form->submit();
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertEquals('/user/edit/' . $user->getId(), $client->getUrl(), 'Invalid url form after submited location');
     $this->assertCount(5, $fields, 'Invalid number fields');
     $this->assertFalse($fields[0]->getParent()->hasElement('label'), 'Redundant error message for email');
     $this->assertEquals('Value can not empty', $fields[1]->getParent()->getElement('label')->getText(), 'Invalid error message for first name');
     $this->assertEquals('Value can not empty', $fields[2]->getParent()->getElement('label')->getText(), 'Invalid error message for last name');
     $this->assertEquals('Value can not empty', $fields[3]->getParent()->getElement('label')->getText(), 'Invalid error message for location');
     $fields[0]->setData('*****@*****.**');
     $fields[1]->setData('First name edit');
     $fields[2]->setData('Last name edit');
     $fields[3]->setData($location2->getId());
     $form->submit();
     $this->assertEquals('/user', $client->getUrl(), 'Invalid url form after submited location');
     $em->clear();
     $users = $em->getRepository('Entity\\User')->findAll();
     $this->assertCount(2, $users, 'Invalid number users');
     $user = $users[1];
     $this->assertEquals('*****@*****.**', $user->getEmail(), 'Invalid user email');
     $this->assertEquals('First name edit', $user->getFirstName(), 'Invalid user first name');
     $this->assertEquals('Last name edit', $user->getLastName(), 'Invalid user last name');
     $this->assertEquals($location2->getId(), $user->getLocation()->getId(), 'Invalid user location');
 }
Exemplo n.º 7
0
 public function testIndex()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $deviceTag = new DeviceTag();
     $deviceTag->setName('DeviceTag name');
     $this->persist($deviceTag);
     $otherUser = new User();
     $otherUser->setEmail('*****@*****.**');
     $otherUser->setFirstName('first name');
     $otherUser->setLastName('last name');
     $otherUser->setLocation($this->user->getLocation());
     $otherUser->setRole($this->user->getRole());
     $this->persist($otherUser);
     $devices = array();
     $devices[0] = new Device();
     $devices[0]->setName('Device name');
     $devices[0]->setPhoto('Device.photo.jpg');
     $devices[0]->getTags()->add($deviceTag);
     $devices[0]->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $devices[0]->setSerialNumber('Device serial number');
     $devices[0]->setState($em->getRepository('Entity\\DeviceState')->findOneById(1));
     $devices[0]->setSymbol('REF1');
     $devices[0]->setLocation($this->user->getLocation());
     $this->persist($devices[0]);
     $devices[1] = new Device();
     $devices[1]->setName('Device name2');
     $devices[1]->setPhoto('Device.photo.jpg');
     $devices[1]->getTags()->add($deviceTag);
     $devices[1]->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $devices[1]->setSerialNumber('Device serial number');
     $devices[1]->setState($em->getRepository('Entity\\DeviceState')->findOneById(2));
     $devices[1]->setSymbol('REF1');
     $devices[1]->setLocation($this->user->getLocation());
     $this->persist($devices[1]);
     $device3 = new Device();
     $device3->setName('Device name other');
     $device3->setPhoto('Device.photo.jpg');
     $device3->getTags()->add($deviceTag);
     $device3->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $device3->setSerialNumber('Device serial number');
     $device3->setState($em->getRepository('Entity\\DeviceState')->findOneById(2));
     $device3->setUser($otherUser);
     $device3->setLocation($otherUser->getLocation());
     $device3->setSymbol('REF1');
     $this->persist($device3);
     $device4 = new Device();
     $device4->setName('Device name other');
     $device4->setPhoto('Device.photo.jpg');
     $device4->getTags()->add($deviceTag);
     $device4->setType($em->getRepository('Entity\\DeviceType')->findOneById(1));
     $device4->setSerialNumber('Device serial number');
     $device4->setState($em->getRepository('Entity\\DeviceState')->findOneById(2));
     $device4->setUser($otherUser);
     $device4->setLocation($this->user->getLocation());
     $device4->setSymbol('REF1');
     $this->persist($device4);
     $this->flush();
     $session = $this->createSession();
     $session->set('user.id', $this->user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/device/location');
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Invalid status code.');
     $tr = $client->getElement('table')->getElement('tbody')->findElements('tr');
     $this->assertCount(2, $tr, 'Invalid number records in grid');
     $ind = 0;
     foreach ($devices as $device) {
         $td = $tr[$ind++]->findElements('td');
         $this->assertCount(6, $td, 'Invalid number columns in grid');
         $this->assertEquals($device->getId(), $td[0]->getText(), 'Invalid data columns id');
         $this->assertEquals($device->getName(), $td[1]->getText(), 'Invalid data columns name');
         $this->assertEquals($device->getSerialNumber(), $td[2]->getText(), 'Invalid data columns serial number');
         $this->assertEquals($device->getType()->getName(), $td[3]->getText(), 'Invalid data columns type');
         $this->assertEquals($device->getState()->getName(), $td[4]->getText(), 'Invalid data columns state');
     }
     $td = $tr[0]->findElements('td');
     $a1 = $td['5']->findElements('a');
     $this->assertCount(1, $a1, 'Invalid buttons number.');
     $assignButton = $a1[0];
     $this->assertEquals('Assign to me', $assignButton->getText(), 'Invalid button label');
     $assignButton->click();
     $this->assertEquals('/device/location/assign/' . $devices[0]->getId(), $client->getUrl(), 'Invalid assign device url');
     $td = $tr[1]->findElements('td');
     $a2 = $td['5']->findElements('a');
     $this->assertCount(2, $a2, 'Invalid buttons number.');
     $freeButton = $a2[0];
     $this->assertEquals('Free', $freeButton->getText(), 'Invalid button label');
     $freeButton->click();
     $this->assertEquals('/device/location/free/' . $devices[1]->getId(), $client->getUrl(), 'Invalid free device url');
     $assignButton = $a2[1];
     $this->assertEquals('Assign to me', $assignButton->getText(), 'Invalid button label');
     $assignButton->click();
     $this->assertEquals('/device/location/assign/' . $devices[1]->getId(), $client->getUrl(), 'Invalid assign device url');
 }