public function setUp() { parent::setUp(); $this->bookRepo = m::mock('Bakgat\\Notos\\Domain\\Model\\Resource\\BookRepository'); $this->org = Organization::register(new Name('VBS De Klimtoren'), new DomainName('klimtoren.be')); $this->spec = new IsbnIsUnique($this->bookRepo); }
/** * @test * @group bookrepo */ public function should_return_empty_set_when_no_books_found() { $n_foo = new Name('foo'); $dn_bar = new DomainName('bar.be'); $foo = Organization::register($n_foo, $dn_bar); $books = $this->bookRepo->all($foo); $this->assertEmpty($books); }
/** * @test * @group calendarrepo */ public function should_return_empty_set() { $n_foo = new Name('foo'); $dn_foo = new DomainName('bar.be'); $foo = Organization::register($n_foo, $dn_foo); $events = $this->calendarRepo->all($foo); $this->assertEmpty($events); }
public function createOrganizations() { $this->klimtoren = Organization::register(new Name('VBS De Klimtoren'), new DomainName('klimtoren.be')); $this->wassenaard = Organization::register(new Name('VBS De Wassenaard'), new DomainName('wassenaard.be')); $this->loopbrug = Organization::register(new Name('VBS De Loopbrug'), new DomainName('deloopbrug.be')); $this->boompje = Organization::register(new Name('VBS \'t Boompje'), new DomainName('tboompje.be')); $this->manager->persist($this->klimtoren); $this->manager->persist($this->wassenaard); $this->manager->persist($this->loopbrug); $this->manager->persist($this->boompje); $this->manager->flush(); }
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']; }
private function getKlimtoren() { $n_org = new Name('VBS De Klimtoren'); $dn_org = new DomainName('klimtoren.be'); $organization = Organization::register($n_org, $dn_org); return $organization; }
/** * @param Organization $organization * @param Isbn $isbn * @return Book */ public function bookOfIsbn(Organization $organization, Isbn $isbn) { $qb = $this->em->createQueryBuilder(); $query = $qb->select('b')->from($this->bookClass, 'b')->where($qb->expr()->eq('b.organization', '?1'), $qb->expr()->eq('b.isbn', '?2'))->setParameter(1, $organization->id())->setParameter(2, $isbn->toString()); return $query->getQuery()->getOneOrNullResult(); }
/** * {@inheritDoc} */ public function relatedTo() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'relatedTo', array()); return parent::relatedTo(); }
/** * 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(); }
/** * @param Organization $organization * @return ArrayCollection */ public function all(Organization $organization) { $qb = $this->em->createQueryBuilder(); $qb->select('a')->from($this->assetClass, 'a')->join('a.organization', 'o')->where($qb->expr()->eq('o.id', ':org'))->setParameter('org', $organization->id()); return $qb->getQuery()->getResult(); }
/** * Shows all events between a timespan (start, end) of one Organization * @param Organization $organization * @param $start * @param $end * @return ArrayCollection */ public function eventsBetween(Organization $organization, $start, $end) { $qb = $this->em->createQueryBuilder(); $qb->select('c')->from($this->calendarClass, 'c')->where($qb->expr()->eq('c.organization', '?1'), $qb->expr()->orX($qb->expr()->andX($qb->expr()->gte('c.start', '?2'), $qb->expr()->lte('c.start', '?3')), $qb->expr()->andX($qb->expr()->gte('c.end', '?2'), $qb->expr()->lte('c.end', '?3'))))->setParameter(1, $organization->id())->setParameter(2, $start)->setParameter(3, $end); return $qb->getQuery()->getResult(); }
/** * Gets all the roles associated with an user * @param User $user * @param Organization $organization * @return mixed */ public function rolesOfUser(User $user, Organization $organization) { $qb = $this->em->createQueryBuilder(); $qb->select('r')->from($this->roleClass, 'r')->join('r.user_roles', 'ur')->where($qb->expr()->eq('ur.user', '?1'), $qb->expr()->eq('ur.organization', '?2'))->setParameter(1, $user->id())->setParameter(2, $organization->id()); return $qb->getQuery()->getResult(); }
/** * @param Organization $organization * @return ArrayCollection */ public function all(Organization $organization) { $qb = $this->em->createQueryBuilder(); $qb->select('b, i')->from($this->blogClass, 'b')->leftJoin('b.image', 'i')->where($qb->expr()->eq('b.organization', '?1'))->orderBy('b.weborder')->setParameter(1, $organization->id()); return $qb->getQuery()->getResult(); }
private function getKlimtoren() { $n_klimtoren = new Name('VBS De Klimtoren'); $dn_klimtoren = new DomainName('klimtoren.be'); $klimtoren = Organization::register($n_klimtoren, $dn_klimtoren); return $klimtoren; }
/** * @test * @group userrepo */ public function should_return_null_when_org_with_acl_not_found() { $username = new Username('*****@*****.**'); $n_foo = new Name('foo'); $dn_foo = new DomainName('bar.be'); $foo = Organization::register($n_foo, $dn_foo); $user = $this->userRepo->userWithACL($username, $foo); $this->assertNull($user); }
public static function register(Name $name, DomainName $domainName) { $org = new Organization($name); $org->setDomainName($domainName); return $org; }
/** * Find a user by their username and load all ACL along * @param Username $username * @param Organization $organization * @return User */ public function userWithACL(Username $username, Organization $organization) { $qb = $this->em->createQueryBuilder(); $qb->select('u, ur, r')->from($this->class, 'u')->join('u.user_roles', 'ur')->join('ur.role', 'r')->where($qb->expr()->eq('u.username', '?1'), $qb->expr()->eq('ur.organization', '?2'))->setParameter(1, $username->toString())->setParameter(2, $organization->id()); return $qb->getQuery()->getOneOrNullResult(); }