Esempio n. 1
0
 public function testGetWikiContent()
 {
     $code = new SubjectFaculty();
     $code->setCampus('UBC');
     $code->setFaculty('ARTS');
     $code->setDepartment('ASIA');
     // mock repository
     $mockSubjectCodeRepository = $this->getMockBuilder('\\UBC\\Exam\\MainBundle\\Entity\\SubjectCodeRepository')->disableOriginalConstructor()->getMock();
     $mockSubjectCodeRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($code));
     // mock the EntityManager to return the mock of the repository
     $entityManager = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($mockSubjectCodeRepository));
     // mock buzz
     $response = $this->getMockBuilder('Buzz\\Message\\Response')->setMethods(array('getContent', 'getStatusCode'))->getMock();
     $response->expects($this->any())->method('getContent')->will($this->returnValue('<p>This is a test</p>'));
     $response->expects($this->any())->method('getStatusCode')->will($this->returnValue(200));
     $buzz = $this->getMockBuilder('\\Buzz\\Browser')->setMethods(array('get'))->disableOriginalConstructor()->getMock();
     $buzz->expects($this->any())->method('get')->with($this->equalTo($this->client->getContainer()->getParameter('wiki_base_url') . urlencode('UBC/ARTS/ASIA')))->will($this->returnValue($response));
     // remove cache
     $this->client->getContainer()->get('doctrine_cache.providers.wiki_content')->delete($code->getCacheKey());
     //        $this->client->getContainer()->set('doctrine.orm.default_entity_manager', $entityManager);
     $this->client->getContainer()->set('buzz', $buzz);
     $crawler = $this->client->request('GET', '/exam/wikicontent/UBC/CHIN');
     $this->assertTrue($this->client->getResponse()->isSuccessful());
     $this->assertGreaterThan(0, $crawler->filter('html:contains("test")')->count());
     // should not call buzz but retrieve from cache
     $client = self::createClient();
     $buzz = $this->getMockBuilder('\\Buzz\\Browser')->disableOriginalConstructor()->getMock();
     $buzz->expects($this->never())->method('get');
     $client->getContainer()->set('buzz', $buzz);
     $crawler = $client->request('GET', '/exam/wikicontent/UBC/CHIN');
 }
Esempio n. 2
0
 public function testRefresh()
 {
     $code = new SubjectFaculty();
     $code->setCode('BIOL');
     $code->setCampus('UBC');
     $code->setDepartment('SCIE');
     $code->setFaculty('ARTS');
     $code->setUrn('urn:ubc:subjectCode:BIOL~UBC');
     $code->setTitle('biology');
     $this->getRepository()->refresh(array($code));
     $codes = $this->getRepository()->findAll();
     $this->assertEquals(1, count($codes), 'should purge old data and load the new ones');
 }
Esempio n. 3
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 function load(ObjectManager $manager)
 {
     $code = new SubjectFaculty();
     $code->setCode('CHIN');
     $code->setCampus('UBC');
     $code->setDepartment('ASIA');
     $code->setFaculty('ARTS');
     $code->setUrn('urn:ubc:subjectCode:CHIN~UBC');
     $code->setTitle('Chinese');
     $manager->persist($code);
     $code = new SubjectFaculty();
     $code->setCode('JAPN');
     $code->setCampus('UBC');
     $code->setDepartment('ASIA');
     $code->setFaculty('ARTS');
     $code->setUrn('urn:ubc:subjectCode:JAPN~UBC');
     $code->setTitle('Japanese');
     $manager->persist($code);
     $manager->flush();
 }
Esempio n. 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('local')) {
         list($subjectCodes, $departmentCodes) = $this->refreshFromLocal($output);
     } else {
         list($subjectCodes, $departmentCodes) = $this->refreshFromSIS($output);
     }
     $output->writeln('Merging codes...');
     // convert department code array to an associate array for searching by code
     $departmentCodeArray = array();
     foreach ($departmentCodes->codes as $code) {
         $departmentCodeArray[$code->getCode()] = $code;
     }
     $entities = array();
     foreach ($subjectCodes->codes as $code) {
         $scode = new SubjectFaculty();
         $scode->setUrn($code->getId());
         //$scode->setCode($code->getCode());
         // temp fix as sis api missing code value for subject_code API
         $c = explode(':', $code->getId());
         $c = explode('~', $c[3]);
         $scode->setCode($c[0]);
         $scode->setCampus($code->getAdminCampusCode());
         $scode->setDepartment($code->getDepartmentCode());
         $scode->setTitle($code->getFullDescription());
         $deptCode = $code->getDepartmentCode();
         if (!empty($deptCode) && array_key_exists($deptCode, $departmentCodeArray)) {
             $departmentCode = $departmentCodeArray[$deptCode];
             $scode->setFaculty($departmentCode->getAdminFacultyCode());
         }
         $entities[] = $scode;
     }
     $output->writeln('Persisting into database...');
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->getRepository('UBCExamMainBundle:SubjectFaculty')->refresh($entities);
     $output->writeln('Done! Loaded ' . count($entities) . ' subject codes.');
 }