protected function setupTestData() { //USER $fname = new Name('Karl'); $lname = new Name('Van Iseghem'); $uname = new Username('*****@*****.**'); $pwd = new HashedPassword(bcrypt('password')); $gender = new Gender(Gender::MALE); $email = new Email($uname->toString()); $this->karl = User::register($fname, $lname, $uname, $pwd, $email, $gender); //ORGANIZATION $orgName = new Name('VBS De Klimtoren'); $domainName = new DomainName('klimtoren.be'); $this->klimtoren = Organization::register($orgName, $domainName); //ACL $role_admin = Role::register('admin'); $role_sa = Role::register('sa'); $this->roleUser = Role::register('user'); UserRole::register($this->karl, $role_admin, $this->klimtoren); UserRole::register($this->karl, $role_sa, $this->klimtoren); $this->userData = ['first_name' => 'Karl', 'last_name' => 'Van Iseghem', 'username' => '*****@*****.**', 'password' => 'password', 'gender' => 'M']; }
/** * Adds a new user to an organization. * * @param $data * @param $orgId * @return User * @throws DuplicateException * @throws OrganizationNotFoundException */ public function add($data, $orgId) { //extract all data from array $firstName = new Name($data['first_name']); $lastName = new Name($data['last_name']); $userName = new Username($data['username']); $hashedPwd = new HashedPassword(bcrypt($data['password'])); $gender = new Gender($data['gender']); $email = null; if (isset($data['reset_email'])) { $email = new Email($data['reset_email']); } else { $email = new Email($data['username']); } //find the organization $organization = $this->organizationOfId($orgId); //only unique usernames $this->checkUsernameIsUnique($userName); //all valid, now GO! $user = User::register($firstName, $lastName, $userName, $hashedPwd, $email, $gender); $this->userRepo->add($user); //make this user a 'user' of the organization $this->addUserToRole($user, 'user', $organization); //return the entire filled profile (ACL included) //TODO speed by manually setting $user->setUserRoles or $user->addUserRole ... to fill getRoles() return $this->getProfile($user->id(), $orgId); }
/** * Load data fixtures with the passed EntityManager * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { /* *************************************************** * USERS * **************************************************/ $fn_karl = new Name('Karl'); $ln_karl = new Name('Van Iseghem'); $un_karl = new Username('*****@*****.**'); $e_karl = new Email($un_karl->toString()); $pwd_karl = new HashedPassword(bcrypt('password')); $g_karl = new Gender(Gender::MALE); $karl = User::register($fn_karl, $ln_karl, $un_karl, $pwd_karl, $e_karl, $g_karl); $fn_reb = new Name('Rebekka'); $ln_reb = new Name('Buyse'); $un_reb = new Username('*****@*****.**'); $e_reb = new Email($un_reb->toString()); $pwd_reb = new HashedPassword(bcrypt('password')); $g_reb = new Gender(Gender::FEMALE); $rebekka = User::register($fn_reb, $ln_reb, $un_reb, $pwd_reb, $e_reb, $g_reb); $manager->persist($karl); $manager->persist($rebekka); /* *************************************************** * ORGANIZATIONS * **************************************************/ $n_klimtoren = new Name('VBS De Klimtoren'); $dn_klimtoren = new DomainName('klimtoren.be'); $klimtoren = Organization::register($n_klimtoren, $dn_klimtoren); $n_wassenaard = new Name('VBS De Wassenaard'); $dn_wassenaard = new DomainName('wassenaard.be'); $wassenaard = Organization::register($n_wassenaard, $dn_wassenaard); $manager->persist($klimtoren); $manager->persist($wassenaard); /* *************************************************** * ASSETS * **************************************************/ $i = 0; //IMAGES while ($i < 5) { $name = new Name('image ' . ++$i); $guid = Guid::generate(); $mime = $i % 2 === 0 ? 'image/jpeg' : 'image/png'; $image = Asset::register($name, $guid, $mime, $klimtoren); $manager->persist($image); } //PDFs while ($i < 10) { $name = new Name('document ' . ++$i); $guid = Guid::generate(); $mime = 'application/pdf'; $pdf = Asset::register($name, $guid, $mime, $klimtoren); $manager->persist($pdf); } /* *************************************************** * ROLES * **************************************************/ $user_role = new Role('user'); $admin_role = new Role('admin'); $sa_role = new Role('sa'); $book_manager_role = new Role('book_manager'); $website_manager_role = new Role('website_manager'); $manager->persist($user_role); $manager->persist($admin_role); $manager->persist($sa_role); $manager->persist($book_manager_role); $manager->persist($website_manager_role); /* *************************************************** * KINDS * **************************************************/ $k_employee = new Kind('employee'); $k_level = new Kind('level'); $k_classgroup = new Kind('classgroup'); $manager->persist($k_employee); $manager->persist($k_level); $manager->persist($k_classgroup); /* *************************************************** * USERROLES * **************************************************/ $karl_user_klimtoren = UserRole::register($karl, $user_role, $klimtoren); $rebekka_user_klimtoren = UserRole::register($rebekka, $user_role, $klimtoren); $karl_user_wassenaard = UserRole::register($karl, $user_role, $wassenaard); $manager->persist($karl_user_klimtoren); $manager->persist($rebekka_user_klimtoren); $manager->persist($karl_user_wassenaard); $karl_sa_klimtoren = UserRole::register($karl, $sa_role, $klimtoren); $karl_website_manager_wassenaard = UserRole::register($karl, $website_manager_role, $wassenaard); $rebekka_book_manager_klimtoren = UserRole::register($rebekka, $book_manager_role, $klimtoren); $rebekka_admin_klimtoren = UserRole::register($rebekka, $admin_role, $klimtoren); $manager->persist($karl_sa_klimtoren); $manager->persist($karl_website_manager_wassenaard); $manager->persist($rebekka_book_manager_klimtoren); $manager->persist($rebekka_admin_klimtoren); /* *************************************************** * GROUPS * **************************************************/ $level_jkl = Group::register(new Name('JK')); $level_jkl->setKind($k_level); $level_okl = Group::register(new Name('OK')); $level_okl->setKind($k_level); $level_l1 = Group::register(new Name('L1')); $level_l1->setKind($k_level); $cg_K1A = Group::register(new Name('1KA')); $cg_K1A->setKind($k_classgroup); $manager->persist($level_jkl); $manager->persist($level_okl); $manager->persist($level_l1); $manager->persist($cg_K1A); /* *************************************************** * COURSES * **************************************************/ $n_maths = new Name('wiskunde'); $maths = Course::register($n_maths); $n_gk = new Name('getallenkennis'); $gk = Course::register($n_gk); $n_lang = new Name('nederlands'); $lang = Course::register($n_lang); $n_sp = new Name('spelling'); $sp = Course::register($n_sp); $manager->persist($maths); $manager->persist($gk); $manager->persist($lang); $manager->persist($sp); /* *************************************************** * CURRICULA * **************************************************/ $curr_maths = new Curriculum($maths, 2009); $curr_maths->setCode('2009/098/098AE'); $manager->persist($curr_maths); $struc = new Structure(); $struc->setName(new Name('chapter 1')); $struc->setType('chapter'); $struc->setCurriculum($curr_maths); $manager->persist($struc); $n_obj = new Name('Doel 1a'); $c_obj = 'D0.1.a'; $objective = Objective::register($n_obj, $c_obj, $struc); $manager->persist($objective); $obj_level = ObjectiveControlLevel::register($cg_K1A, $objective, 1); $manager->persist($obj_level); /* *************************************************** * TAGS * **************************************************/ $tag1 = Tag::register(new TagName('tag1')); $tag2 = Tag::register(new TagName('tag2')); $manager->persist($tag1); $manager->persist($tag2); $tags = [$tag1, $tag2]; /* *************************************************** * WEBSITES * **************************************************/ $sites = [['name' => 'Google', 'url' => 'www.google.be'], ['name' => 'VBS De Klimtoren', 'url' => 'www.klimtoren.be'], ['name' => 'Apple', 'url' => 'www.apple.com/benl'], ['name' => 'De Wassenaard', 'url' => 'www.wassenaard.be'], ['name' => 'Rekenmeester', 'url' => 'www.rekenmeester.be'], ['name' => 'C.A.R.E', 'url' => 'http://care-india.be/'], ['name' => 'VBS Ichtegem', 'url' => 'www.vbsichtegem.be'], ['name' => 'Replay', 'url' => 'http://www.replaycoverband.be'], ['name' => 'HP', 'url' => 'http://www.hp.com'], ['name' => 'Microsoft', 'url' => 'http://www.microsoft.com/']]; foreach ($sites as $site) { $n_s = new Name($site['name']); $u_s = new URL($site['url']); $s = Website::register($n_s, $u_s); $s->addTag($tags[rand(0, 1)]); $manager->persist($s); } /* *************************************************** * BLOGS * **************************************************/ $n_blog1 = new Name('blog 1'); $url_blog1 = new URL('www.blog1.bar'); $blog1 = Blog::register($n_blog1, $url_blog1, $klimtoren); $blog1->setWeborder(1); $n_blog2 = new Name('blog 2'); $url_blog2 = new URL('www.blog2.bar'); $blog2 = Blog::register($n_blog2, $url_blog2, $klimtoren); $blog2->setWeborder(2); $n_blog3 = new Name('blog 3'); $url_blog3 = new URL('www.blog3.bar'); $blog3 = Blog::register($n_blog3, $url_blog3, $wassenaard); $blog3->setWeborder(1); $manager->persist($blog1); $manager->persist($blog2); $manager->persist($blog3); /* *************************************************** * BOOKS * **************************************************/ $i = 0; $isbns = ['9782123456803', '9789027439642', '9789023487197', '9780080490984', '9780500093832']; while ($i < 5) { $isbn = new Isbn($isbns[$i++]); $n_book = new Name('book ' . $i); $book = Book::register($n_book, $isbn); $book->setOrganization($klimtoren); $manager->persist($book); } /* *************************************************** * EVENTS * **************************************************/ $i = 0; //5 in the future while ($i < 5) { $n_event = new Name('event ' . ++$i); $s_int = mt_rand(1462104000, 1515758400); // 1/5/2016 - 12/12/2018 $s_date = date("Y-m-d H:i:s", $s_int); $event = CalendarEvent::register($n_event, $klimtoren, new DateTime($s_date)); if ($i < 4) { $event->addGroup($cg_K1A); } $manager->persist($event); } //5 in the past while ($i < 10) { $n_event = new Name('event ' . ++$i); $s_int = mt_rand(957182400, 1241179200); // 1/5/2000 - 1/5/2009 $s_date = date("Y-m-d H:i:s", $s_int); $event = CalendarEvent::register($n_event, $klimtoren, new DateTime($s_date)); if ($i < 9) { $event->addGroup($cg_K1A); } $manager->persist($event); } $manager->flush(); }
public function createUsers() { $male = new Gender('m'); $female = new Gender('f'); $users = [['fn' => 'Karl', 'ln' => 'Van Iseghem', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->klimtoren, $this->wassenaard, $this->boompje, $this->loopbrug], 'roles' => [$this->sa]], ['fn' => 'Bart', 'ln' => 'Verfaillie', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->wassenaard], 'roles' => [$this->website_moderator]], ['fn' => 'Lut', 'ln' => 'Ghyoot', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->wassenaard], 'roles' => [$this->website_moderator]], ['fn' => 'Geertrui', 'ln' => 'Deprijcker', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->loopbrug], 'roles' => [$this->website_moderator]], ['fn' => 'Myriam', 'ln' => 'Monstrey', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->loopbrug], 'roles' => [$this->website_moderator]], ['fn' => 'Annemie', 'ln' => 'Demaré', 'un' => '*****@*****.**', 'pwd' => 'password', 'realms' => [$this->boompje], 'roles' => [$this->website_moderator]]]; $emp = $this->kindRepo->get('employee'); foreach ($users as $arr_user) { //CREATE USER $firstName = new Name($arr_user['fn']); $lastName = new Name($arr_user['ln']); $userName = new Username($arr_user['un']); $pwd = new HashedPassword(bcrypt($arr_user['pwd'])); $reset_email = new Email($userName->toString()); $user = User::register($firstName, $lastName, $userName, $pwd, $reset_email, $male); $this->manager->persist($user); //SET RELATION // $rel = PartyRelation::register($user, $arr_user['realms'][0], $emp); //$this->manager->merge($rel); //Set Roles foreach ($arr_user['roles'] as $role) { $ur = UserRole::register($user, $role, $arr_user['realms'][0]); $this->manager->persist($ur); } foreach ($arr_user['realms'] as $realm) { $ur = UserRole::register($user, $this->user_role, $realm); $this->manager->persist($ur); } } $this->manager->flush(); }
/** * @test * @group userrepo */ public function should_return_null_organizations_for_foo() { $fn_foo = new Name('foo'); $ln_foo = new Name('bar'); $un_foo = new Username('*****@*****.**'); $e_foo = new Email($un_foo->toString()); $pwd_foo = new HashedPassword(bcrypt('password')); $g_foo = new Gender(Gender::OTHER); $foo = User::register($fn_foo, $ln_foo, $un_foo, $pwd_foo, $e_foo, $g_foo); $organizations = $this->userRepo->organizationsOfUser($foo); $this->assertEmpty($organizations); }