示例#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;
 }
示例#2
0
 public function testSetLocation()
 {
     $em = $this->getService('doctrine')->getEntityManager();
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('first name');
     $user->setLastName('last name');
     $this->persist($user);
     $this->flush();
     $location = $this->getService('doctrine')->getRepository('Entity\\Location')->findOneBy(array());
     $session = $this->createSession();
     $session->set('user.id', $user->getId());
     $client = $this->createClient($session);
     $client->loadPage('/');
     $this->assertEquals('/login/location', $client->getUrl(), 'invalid url');
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertCount(1, $fields, 'Invalid number fields');
     $fields[0]->setData('');
     $form->submit();
     $form = $client->getElement('form');
     $fields = $form->getFields();
     $this->assertEquals('/login/location', $client->getUrl(), 'Invalid url form after submited form');
     $this->assertEquals('Value can not empty', $fields[0]->getParent()->getElement('label')->getText(), 'Invalid error message for location');
     $fields[0]->setData($location->getId());
     $form->submit();
     $this->assertEquals('/', $client->getUrl(), 'Invalid url form after submited form');
     $em->clear();
     $users = $em->getRepository('Entity\\User')->findAll();
     $this->assertCount(2, $users, 'Invalid number users');
     $user = $users[1];
     $this->assertEquals($location->getId(), $user->getLocation()->getId(), 'Invalid location');
     $client->loadPage('/login/location');
     $this->assertEquals('/', $client->getUrl(), 'Invalid url after set location');
 }
示例#3
0
 public function createAdmin($email, $username, $password, $roles, $lastName = '', $firstName = '')
 {
     $user = new User();
     $user->setEmail($email);
     $user->setEnabled(0);
     $user->setUsername($username);
     $user->setSubscribe(new \DateTime('now'));
     $user->setRoles(serialize($roles));
     $user->setLastName($lastName);
     $user->setFirstName($firstName);
     $salt = uniqid(mt_rand(), true);
     $options = ['cost' => 11, 'salt' => $salt];
     $user->setSalt($salt);
     $user->setPassword(password_hash($password, PASSWORD_BCRYPT, $options));
     $this->em->persist($user);
     $this->em->flush();
 }
示例#4
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 setEmail($email)
 {
     $this->__load();
     return parent::setEmail($email);
 }
 /**
  * {@inheritDoc}
  */
 public function setEmail($email)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setEmail', [$email]);
     return parent::setEmail($email);
 }
示例#7
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');
 }
示例#8
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());
 }
示例#9
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');
 }
示例#10
0
<?php

require_once 'before.php';
use Entity\User;
$pagename = "Registration";
$useremail = "";
$userpassword = "";
$userdescription = "";
$userfirstname = "";
$userlastname = "";
$userdate = "";
if (isset($_POST['UserEmail']) && isset($_POST['UserPassword']) && isset($_POST['UserDescription']) && isset($_POST['UserFirstname']) && isset($_POST['UserLastname']) && isset($_POST['UserDate'])) {
    if (!$userLoggedIn) {
        //add user registration and handle errors
        $newuser = new User();
        $newuser->setEmail(htmlentities($_POST['UserEmail']));
        $newuser->setPassword(htmlentities($_POST['UserPassword']));
        $newuser->setDescription(htmlentities($_POST['UserDescription']));
        $newuser->setFirstname(htmlentities($_POST['UserFirstname']));
        $newuser->setLastname(htmlentities($_POST['UserLastname']));
        $date = DateTime::createFromFormat('Y-m-d', $_POST['UserDate']);
        $newuser->setBirthDate($date);
        $em->persist($newuser);
        $em->flush($newuser);
        $_SESSION['success'] = "You have been registered";
        header('Location: threads.php');
    } else {
        $_SESSION['success'] = "You are logged in.";
        header('Location: threads.php');
    }
} else {
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userTypeAdmin = $this->getReference('TYPE_ADMIN');
     $userTypeNormal = $this->getReference('TYPE_NORMAL');
     $dummyData = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget sollicitudin elit.\n                Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis ut turpis quis ante mattis luctus.\n                Fusce ac tortor purus. Pellentesque blandit scelerisque sagittis. Morbi quis dolor molestie, mattis felis quis, eleifend lorem.\n                Fusce rhoncus mauris sit amet sapien feugiat, quis ultricies nunc semper.";
     $encoder = $this->container->get('security.password_encoder');
     //User 1
     $user = new User();
     $user->setFirstName('Robert');
     $user->setLastName('Delson');
     $user->setEmail('*****@*****.**');
     $user->setStatus('A');
     $userAuth = new UserAuth();
     $userAuth->setUsername('super');
     $userAuth->setSalt($userAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($user, 'admin');
     $userAuth->setPassword($password);
     $userAuth->setAlgorithm('sha1');
     $adminRole = $this->getReference('ROLE_ADMIN');
     $user->addUserRole($adminRole);
     $user->setUserType($userTypeAdmin);
     $userAuth->setUser($user);
     $manager->persist($userAuth);
     // User 2
     $puser = new User();
     $puser->setFirstName('Mark');
     $puser->setLastName('Philips');
     $puser->setEmail('*****@*****.**');
     $puser->setStatus('A');
     $puserAuth = new UserAuth();
     $puserAuth->setUsername('rmc');
     $puserAuth->setSalt($puserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($puser, 'change20');
     $puserAuth->setPassword($password);
     $puserAuth->setAlgorithm('sha1');
     $padminRole = $this->getReference('ROLE_ADMIN');
     $puser->addUserRole($padminRole);
     $puser->setUserType($userTypeAdmin);
     $puserAuth->setUser($puser);
     $manager->persist($puserAuth);
     // add normal users
     $rolePrivate = $this->getReference('ROLE_PRIVATE');
     $roleCompany = $this->getReference('ROLE_COMPANY');
     // Normal User 1
     $nuser1 = new User();
     $nuser1->setFirstName('Mitesh');
     $nuser1->setLastName('Vasava');
     $nuser1->setEmail('*****@*****.**');
     $nuser1->setStatus('A');
     $nuserAuth = new UserAuth();
     $nuserAuth->setUsername('*****@*****.**');
     $nuserAuth->setSalt($nuserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($nuser1, 'mitesh');
     $nuserAuth->setPassword($password);
     $nuserAuth->setAlgorithm('sha1');
     $nuserAuth->setTotalLogin(2);
     $nuser1->addUserRole($roleCompany);
     $nuser1->setUserType($userTypeNormal);
     $nuser1->setAddress('Romania');
     $nuser1->setPhone('9302302014');
     $nuserAuth->setUser($nuser1);
     $manager->persist($nuserAuth);
     // Normal User 2
     $nuser2 = new User();
     $nuser2->setFirstName('Denial');
     $nuser2->setLastName('Bosco');
     $nuser2->setEmail('*****@*****.**');
     $nuser2->setStatus('A');
     $nuserAuth = new UserAuth();
     $nuserAuth->setUsername('*****@*****.**');
     $nuserAuth->setSalt($nuserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($nuser2, 'change20');
     $nuserAuth->setPassword($password);
     $nuserAuth->setAlgorithm('sha1');
     $nuserAuth->setTotalLogin(0);
     $nuser2->addUserRole($rolePrivate);
     $nuser2->setUserType($userTypeNormal);
     $nuserAuth->setUser($nuser2);
     $manager->persist($nuserAuth);
     // Normal User 3
     $nuser3 = new User();
     $nuser3->setFirstName('Anirudh');
     $nuser3->setLastName('Zala');
     $nuser3->setEmail('*****@*****.**');
     $nuser3->setAddress('India');
     $nuser3->setPhone('9302342014');
     $nuser3->setStatus('A');
     $nuserAuth = new UserAuth();
     $nuserAuth->setUsername('*****@*****.**');
     $nuserAuth->setSalt($nuserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($nuser3, 'change20');
     $nuserAuth->setPassword($password);
     $nuserAuth->setAlgorithm('sha1');
     $nuserAuth->setTotalLogin(4);
     $nuser3->addUserRole($roleCompany);
     $nuser3->setUserType($userTypeNormal);
     $nuserAuth->setUser($nuser3);
     $manager->persist($nuserAuth);
     // Normal User 4
     $nuser4 = new User();
     $nuser4->setFirstName('Claudia');
     $nuser4->setLastName('Nessler');
     $nuser4->setEmail('*****@*****.**');
     $nuser4->setAddress('Gartenweg 8');
     $nuser4->setPhone('3111112354');
     $nuser4->setMobile('9302202014');
     $nuser4->setFax('9202302014');
     $nuser4->setStatus('A');
     $nuserAuth = new UserAuth();
     $nuserAuth->setUsername('*****@*****.**');
     $nuserAuth->setSalt($nuserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($nuser4, 'cahnge20');
     $nuserAuth->setPassword($password);
     $nuserAuth->setAlgorithm('sha1');
     $nuserAuth->setTotalLogin(1);
     $nuser4->addUserRole($roleCompany);
     $nuser4->setUserType($userTypeNormal);
     $nuserAuth->setUser($nuser4);
     $manager->persist($nuserAuth);
     // Normal User 5
     $nuser5 = new User();
     $nuser5->setFirstName('Larry');
     $nuser5->setLastName('Page');
     $nuser5->setEmail('*****@*****.**');
     $nuser5->setStatus('A');
     $nuserAuth = new UserAuth();
     $nuserAuth->setUsername('*****@*****.**');
     $nuserAuth->setSalt($nuserAuth->getRandomSalt());
     // password encoder service to encode password
     $password = $encoder->encodePassword($nuser5, 'change20');
     $nuserAuth->setPassword($password);
     $nuserAuth->setAlgorithm('sha1');
     $nuserAuth->setTotalLogin(0);
     $nuser5->addUserRole($rolePrivate);
     $nuser5->setUserType($userTypeNormal);
     $nuserAuth->setUser($nuser5);
     $manager->persist($nuserAuth);
     // flush persisted data
     $manager->flush();
     $this->addReference('user_admin', $user);
     $this->addReference('user_normal_1', $nuser1);
     $this->addReference('user_normal_2', $nuser2);
     $this->addReference('user_normal_3', $nuser3);
     $this->addReference('user_normal_4', $nuser4);
     $this->addReference('user_normal_5', $nuser5);
 }
示例#12
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');
 }
/**
 * Fonction permettant de vérifier si le formulaire de modification de profil est correct et si il ne contient pas d'erreurs.
 * @param User $user : l'utilisateur qui a fait la demande de changement de profil.
 * @return array : un tableau contenant tous les messages d'erreur liés au formulaire de changement de profil ou un booleen
 * si le formulaire est correct.
 */
function isValidForm(User $user)
{
    $config = getConfigFile()['CONSTANTE'];
    $UserName = $_POST['userName'];
    $Email = $_POST['email'];
    $Mdp = $_POST['Mdp'];
    $MdpBis = $_POST['MdpBis'];
    $tel = $_POST['Tel'];
    $MdpActuel = $_POST['MdpActuel'];
    if ($Mdp == '') {
        $Mdp = NULL;
        $MdpBis = NULL;
    }
    $userTest = new User(array("UserName" => $UserName, "email" => $Email, "Mdp" => $Mdp, "tel" => $tel));
    $tab = array("RETURN" => false, "ERROR" => array());
    $nameValable = false;
    $emailValable = false;
    $mdpValable = false;
    $nameExistant = false;
    $mailExistant = false;
    $goodMdp = false;
    $boolean_name = false;
    $boolean_mdp = false;
    $mdpIdentique = false;
    $noMdp = false;
    $um = new UserManager(connexionDb());
    $nameVerif = $um->getUserByUserName($userTest->getUserName());
    if ($nameVerif->getUserName() != NULL && $user->getUserName() != $UserName) {
        $nameExistant = true;
        $tab['ERROR']['Name'] = "Nom déjà existant ";
    }
    if (champsEmailValable($Email)) {
        $emailValable = true;
    } else {
        $tab['ERROR']['EmailValable'] = "Votre email contient des caractères indésirables";
    }
    if (champsEmailValable($UserName)) {
        $nameValable = true;
    } else {
        $tab['ERROR']['NameValable'] = "Votre nom d'utilisateur contient des caractères indésirables";
    }
    $mailVerif = $um->getUserByEmail($userTest->getEmail());
    if ($mailVerif->getUserName() != NULL && $user->getEmail() != $Email) {
        $mailExistant = true;
        $tab['ERROR']['Email'] = "Email déjà existant";
    }
    if ($user->getMdp() == hash("sha256", $MdpActuel . $user->getSalt())) {
        $goodMdp = true;
    } else {
        $tab['ERROR']['MdpActuel'] = "Mauvais mot de passe actuel ! Annulation de la modification";
    }
    if (isset($UserName) and strlen($UserName) >= $config['size_user_name']) {
        $boolean_name = true;
    } else {
        $tab['ERROR']['UserName'] = "******" . $config['size_user_name'] . ")";
    }
    if (isset($Mdp) and isset($MdpBis) and $Mdp == $MdpBis and $Mdp != NULL) {
        if (strlen($Mdp) >= $config['size_user_mdp']) {
            $boolean_mdp = true;
        } else {
            $tab['ERROR']['Mdp'] = "Mots de passe trop court (min: " . $config['size_user_mdp'] . ")";
        }
        if (champsMdpValable($Mdp)) {
            $mdpValable = true;
        } else {
            $tab['ERROR']['mdpValable'] = "Votre mot de passe contient des caractères indésirables";
        }
    } else {
        $noMdp = true;
    }
    if (isset($Mdp) and isset($MdpBis) and $Mdp != $MdpBis) {
        $tab['ERROR']['Mdp'] = "Le mot de passe et le mot de passe de vérification sont différents";
    } else {
        $mdpIdentique = true;
    }
    $tab['RETURN'] = ($boolean_mdp && $mdpValable || $noMdp and $boolean_name and !$nameExistant and !$mailExistant and $goodMdp && $mdpIdentique && $nameValable && $emailValable);
    if ($tab['RETURN']) {
        if (isset($UserName) and $userTest->getUserName() != $user->getUserName()) {
            $user->setUserName($UserName);
        }
        if (isset($Email) and $userTest->getEmail() != $user->getEmail()) {
            $user->setEmail($Email);
        }
        if (isset($Mdp) and strlen($Mdp) > 4 and hash("sha256", $userTest->getMdp() . $userTest->getSalt()) != $user->getMdp()) {
            $user->setMdp($Mdp);
            $user->setHashMdp();
        }
        if (isset($tel) and $tel != $user->getTel()) {
            $user->setTel($tel);
        }
        $um->updateUserProfil($user);
        $userToReconnect = $um->getUserById($user->getId());
        setSessionUser($userToReconnect);
    }
    return $tab;
}