Ejemplo n.º 1
0
 /**
  * @covers \Ilios\CoreBundle\Entity\Course::removeObjective
  */
 public function testRemoveObjectiveWithSessionChildren()
 {
     $sessionObjective = m::mock('Ilios\\CoreBundle\\Entity\\Objective');
     $session = m::mock('Ilios\\CoreBundle\\Entity\\Session');
     $this->object->addSession($session);
     $courseObjective = m::mock('Ilios\\CoreBundle\\Entity\\Objective');
     $courseObjective->shouldReceive('addCourse')->with($this->object)->once();
     $courseObjective->shouldReceive('removeCourse')->with($this->object)->once();
     $session->shouldReceive('getObjectives')->andReturn([$sessionObjective])->once();
     $sessionObjective->shouldReceive('removeParent')->with($courseObjective)->once();
     $this->object->addObjective($courseObjective);
     $this->object->removeObjective($courseObjective);
 }
Ejemplo n.º 2
0
 /**
  * @covers Ilios\CoreBundle\Entity\Course::__construct
  */
 public function testConstructor()
 {
     $this->assertEmpty($this->object->getCohorts());
     $this->assertEmpty($this->object->getDirectors());
     $this->assertEmpty($this->object->getDisciplines());
     $this->assertEmpty($this->object->getMeshDescriptors());
     $this->assertEmpty($this->object->getObjectives());
 }
 /**
  * @return array
  */
 public function testExecuteNoRecipientsConfiguredProvider()
 {
     $school = new School();
     $course = new Course();
     $course->setSchool($school);
     $session = new Session();
     $session->setCourse($course);
     $offering = new Offering();
     $offering->setId(1);
     $offering->setSession($session);
     $alert = new Alert();
     $alert->setId(1);
     $alert->setTableName('offering');
     $alert->setTableRowId($offering->getId());
     return [[$alert, $offering]];
 }
Ejemplo n.º 4
0
 public function load(ObjectManager $manager)
 {
     $data = $this->container->get('ilioscore.dataloader.course')->getAll();
     foreach ($data as $arr) {
         $entity = new Course();
         $entity->setId($arr['id']);
         $entity->setTitle($arr['title']);
         $entity->setLevel($arr['level']);
         $entity->setYear($arr['year']);
         $entity->setStartDate(new \DateTime($arr['startDate']));
         $entity->setEndDate(new \DateTime($arr['endDate']));
         $entity->setDeleted($arr['deleted']);
         $entity->setExternalId($arr['externalId']);
         $entity->setLocked($arr['locked']);
         $entity->setArchived($arr['archived']);
         $entity->setSchool($this->getReference('schools' . $arr['school']));
         $entity->setClerkshipType($this->getReference('courseClerkshipTypes' . $arr['clerkshipType']));
         if (!empty($arr['publishEvent'])) {
             $entity->setPublishEvent($this->getReference('publishEvents' . $arr['publishEvent']));
         }
         foreach ($arr['cohorts'] as $id) {
             $entity->addCohort($this->getReference('cohorts' . $id));
         }
         foreach ($arr['directors'] as $id) {
             $entity->addDirector($this->getReference('users' . $id));
         }
         foreach ($arr['topics'] as $id) {
             $entity->addTopic($this->getReference('topics' . $id));
         }
         foreach ($arr['objectives'] as $id) {
             $entity->addObjective($this->getReference('objectives' . $id));
         }
         $manager->persist($entity);
         $this->addReference('courses' . $arr['id'], $entity);
     }
     $manager->flush();
 }
 /**
  * @return OfferingInterface
  *
  * @todo This is truly in bad form. Refactor fixture loading out. [ST 2015/09/25]
  */
 protected function createOffering()
 {
     $school = new School();
     $school->setId(1);
     $school->setIliosAdministratorEmail('*****@*****.**');
     $school->setTemplatePrefix('TEST');
     $school->setTitle('Testing');
     $course = new Course();
     $course->setId(1);
     $course->setTitle('Test Course 1');
     $course->setSchool($school);
     $i = 0;
     foreach (['A', 'B', 'C'] as $letter) {
         $courseObjective = new Objective();
         $courseObjective->setId(++$i);
         $courseObjective->setTitle("Course Objective {$letter}");
         $course->addObjective($courseObjective);
     }
     $session = new Session();
     $session->setId(1);
     $session->setTitle('Test Session 1');
     $session->setCourse($course);
     $sessionType = new SessionType();
     $sessionType->setId(1);
     $sessionType->setTitle('Session Type A');
     $session->setSessionType($sessionType);
     $i = 0;
     foreach (['A', 'B', 'C'] as $letter) {
         $sessionObjective = new Objective();
         $sessionObjective->setId(++$i);
         $sessionObjective->setTitle("Session Objective {$letter}");
         $session->addObjective($sessionObjective);
     }
     $instructor1 = new User();
     $instructor1->setId(1);
     $instructor1->setFirstName('Jane');
     $instructor1->setLastName('Doe');
     $instructor1->setEmail('*****@*****.**');
     $instructor2 = new User();
     $instructor2->setId(2);
     $instructor2->setFirstName('Mike');
     $instructor2->setLastName('Smith');
     $instructor2->setEmail('*****@*****.**');
     $instructorGroup = new InstructorGroup();
     $instructorGroup->setId(1);
     $instructorGroup->addUser($instructor2);
     $learnerGroup = new LearnerGroup();
     $learnerGroup->setId(1);
     $learnerGroup->setTitle('Learner Group A');
     $learner = new User();
     $learner->setId(2);
     $learner->setFirstName('Jimmy');
     $learner->setLastName('Dumas');
     $offering = new Offering();
     $offering->setId(1);
     $offering->setStartDate(new \DateTime('2015-09-28 03:45:00', new \DateTimeZone('UTC')));
     $offering->setEndDate(new \DateTime('2015-09-28 05:45:00', new \DateTimeZone('UTC')));
     $offering->setSession($session);
     $offering->addInstructor($instructor1);
     $offering->addInstructorGroup($instructorGroup);
     $offering->addLearner($learner);
     $offering->addLearnerGroup($learnerGroup);
     $offering->setRoom('Library - Room 119');
     return $offering;
 }
Ejemplo n.º 6
0
 /**
  * @covers \Ilios\CoreBundle\Entity\Session::getSchool
  */
 public function testGetSchool()
 {
     $school = new School();
     $course = new Course();
     $session = new Session();
     $course->setSchool($school);
     $session->setCourse($course);
     $this->assertSame($school, $session->getSchool());
     $course = new Course();
     $session = new Session();
     $session->setCourse($course);
     $this->assertNull($session->getSchool());
     $session = new Session();
     $this->assertNull($session->getSchool());
 }
Ejemplo n.º 7
0
 /**
  * Gets a basic filled out course
  *
  * @return Course
  */
 protected function createTestCourse()
 {
     $course = new Course();
     $course->setId(10);
     $course->setTitle('test course');
     $course->setLevel(1);
     $now = new DateTime();
     $course->setYear((int) $now->format('Y'));
     $course->setStartDate(new DateTime('yesterday'));
     $course->setEndDate(new DateTime('tomorrow'));
     $course->setExternalId('I45');
     $course->setLocked(true);
     $course->setArchived(true);
     $course->setPublished(true);
     $course->setPublishedAsTbd(true);
     return $course;
 }
Ejemplo n.º 8
0
 public function load(ObjectManager $manager)
 {
     $data = $this->container->get('ilioscore.dataloader.course')->getAll();
     foreach ($data as $arr) {
         $entity = new Course();
         $entity->setId($arr['id']);
         $entity->setTitle($arr['title']);
         $entity->setLevel($arr['level']);
         $entity->setYear($arr['year']);
         $entity->setStartDate(new \DateTime($arr['startDate']));
         $entity->setEndDate(new \DateTime($arr['endDate']));
         $entity->setExternalId($arr['externalId']);
         $entity->setLocked($arr['locked']);
         $entity->setArchived($arr['archived']);
         $entity->setPublishedAsTbd($arr['publishedAsTbd']);
         $entity->setPublished($arr['published']);
         $entity->setSchool($this->getReference('schools' . $arr['school']));
         if (array_key_exists('ancestor', $arr)) {
             $entity->setAncestor($this->getReference('courses' . $arr['ancestor']));
         }
         if (isset($arr['clerkshipType'])) {
             $entity->setClerkshipType($this->getReference('courseClerkshipTypes' . $arr['clerkshipType']));
         }
         foreach ($arr['cohorts'] as $id) {
             $entity->addCohort($this->getReference('cohorts' . $id));
         }
         foreach ($arr['directors'] as $id) {
             $entity->addDirector($this->getReference('users' . $id));
         }
         foreach ($arr['administrators'] as $id) {
             $entity->addAdministrator($this->getReference('users' . $id));
         }
         foreach ($arr['terms'] as $id) {
             $entity->addTerm($this->getReference('terms' . $id));
         }
         foreach ($arr['objectives'] as $id) {
             $entity->addObjective($this->getReference('objectives' . $id));
         }
         foreach ($arr['meshDescriptors'] as $id) {
             $entity->addMeshDescriptor($this->getReference('meshDescriptors' . $id));
         }
         $manager->persist($entity);
         $this->addReference('courses' . $arr['id'], $entity);
     }
     $manager->flush();
 }
Ejemplo n.º 9
0
 /**
  * @covers \Ilios\CoreBundle\Entity\Manager\PermissionManager::userHasReadPermissionToCoursesInSchool
  */
 public function testUserHasReadPermissionToCoursesBySchool()
 {
     $schoolA = new School();
     $schoolA->setId(100);
     $schoolB = new School();
     $schoolB->setId(200);
     $schoolC = new School();
     $schoolC->setId(300);
     $courseA = new Course();
     $courseA->setId(1);
     $schoolA->addCourse($courseA);
     $courseB = new Course();
     $courseB->setId(2);
     $schoolB->addCourse($courseB);
     $coursePermissionA = new Permission();
     $coursePermissionA->setTableRowId(1);
     $user = new User();
     $class = 'Ilios\\CoreBundle\\Entity\\Permission';
     $em = m::mock('Doctrine\\ORM\\EntityManager');
     $repository = m::mock('Doctrine\\ORM\\Repository')->shouldReceive('findOneBy')->with(['tableName' => 'course', 'canRead' => true, 'user' => $user, 'tableRowId' => $courseA->getId()], null)->andReturn([$coursePermissionA])->mock();
     $registry = m::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry')->shouldReceive('getManagerForClass')->andReturn($em)->shouldReceive('getRepository')->andReturn($repository)->mock();
     $manager = new PermissionManager($registry, $class);
     $this->assertFalse($manager->userHasReadPermissionToCoursesInSchool($user, null));
     $this->assertTrue($manager->userHasReadPermissionToCoursesInSchool($user, $schoolA));
     $repository = m::mock('Doctrine\\ORM\\Repository')->shouldReceive('findOneBy')->with(['tableName' => 'course', 'canRead' => true, 'user' => $user, 'tableRowId' => $courseB->getId()], null)->andReturn(null)->mock();
     $registry = m::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry')->shouldReceive('getManagerForClass')->andReturn($em)->shouldReceive('getRepository')->andReturn($repository)->mock();
     $manager = new PermissionManager($registry, $class);
     $this->assertFalse($manager->userHasReadPermissionToCoursesInSchool($user, $schoolB));
     $repository = m::mock('Doctrine\\ORM\\Repository')->shouldNotReceive('findOneBy')->mock();
     $registry = m::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry')->shouldReceive('getManagerForClass')->andReturn($em)->shouldReceive('getRepository')->andReturn($repository)->mock();
     $manager = new PermissionManager($registry, $class);
     $this->assertFalse($manager->userHasReadPermissionToCoursesInSchool($user, $schoolC));
 }
Ejemplo n.º 10
0
 public function testCommandPrintsOutNewCourseIdOnSuccess()
 {
     $courseId = '1';
     $newAcademicYear = '2017';
     $newCourseId = 5;
     $this->service->shouldReceive('rolloverCourse')->andReturnUsing(function () use($newCourseId) {
         $course = new Course();
         $course->setId($newCourseId);
         return $course;
     });
     $this->commandTester->execute(['command' => self::COMMAND_NAME, 'courseId' => $courseId, 'newAcademicYear' => $newAcademicYear]);
     $this->service->shouldHaveReceived('rolloverCourse')->withAnyArgs()->once();
     $output = $this->commandTester->getDisplay();
     $this->assertEquals("This course has been rolled over. The new course id is {$newCourseId}.", trim($output));
 }