/** * Setting entity from form data * * @param \Entity\DeviceType $entity * @param $data */ private function setEntity($entity, $data) { $entity->setName($data['name']); if (array_key_exists('symbolPrefix', $data)) { $entity->setSymbolPrefix($data['symbolPrefix']); } $this->persist($entity); }
public function testRemove() { $em = $this->getService('doctrine')->getEntityManager(); $deviceType = new DeviceType(); $deviceType->setName('Test type'); $deviceType->setSymbolPrefix('TEST'); $this->persist($deviceType); $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($deviceType); $device->setSerialNumber('Device serial number'); $device->setState($em->getRepository('Entity\\DeviceState')->findOneById(1)); $device->setLocation($location); $device->setSymbol($deviceType->getSymbolPrefix() . '1'); $this->persist($device); $this->flush(); $session = $this->createSession(); $session->set('user.id', $this->user->getId()); $client = $this->createClient($session); $client->loadPage('/devicetype/remove/' . $deviceType->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('/devicetype', $client->getUrl(), 'Invalid url button NO.'); $buttons[0]->click(); $this->assertEquals('/devicetype', $client->getUrl(), 'Invalid url button YES.'); //check removed in database $this->assertCount(2, $em->getRepository('Entity\\DeviceType')->findAll()); $this->assertCount(0, $em->getRepository('Entity\\Device')->findAll()); }