Esempio n. 1
0
 private function initServiceKernel()
 {
     $serviceKernel = ServiceKernel::create('dev', false);
     $serviceKernel->setConnection($this->getContainer()->get('database_connection'));
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 1, 'nickname' => '测试管理员', 'currentIp' => '127.0.0.1', 'roles' => array("ROLE_SUPER_ADMIN")));
     $serviceKernel->setCurrentUser($currentUser);
 }
Esempio n. 2
0
function setCurrentUser($user)
{
    $currentUser = new CurrentUser();
    if (empty($user)) {
        $user = array('id' => 0, 'nickname' => '游客', 'currentIp' => '', 'roles' => array());
    }
    $currentUser->fromArray($user);
    ServiceKernel::instance()->setCurrentUser($currentUser);
}
Esempio n. 3
0
 private function initServiceKernel()
 {
     $serviceKernel = ServiceKernel::create('dev', false);
     $serviceKernel->setParameterBag($this->getContainer()->getParameterBag());
     $serviceKernel->setConnection($this->getContainer()->get('database_connection'));
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => '127.0.0.1', 'roles' => array()));
     $serviceKernel->setCurrentUser($currentUser);
 }
Esempio n. 4
0
 protected function initServiceKernel()
 {
     $serviceKernel = ServiceKernel::create('dev', true);
     $serviceKernel->setParameterBag($this->getContainer()->getParameterBag());
     $serviceKernel->registerModuleDirectory(dirname(__DIR__) . '/plugins');
     $serviceKernel->setConnection($this->getContainer()->get('database_connection'));
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => '127.0.0.1', 'roles' => array()));
     $serviceKernel->setCurrentUser($currentUser);
 }
 /**
  * @group delete
  */
 public function testDeleteCommonAdmin()
 {
     $currentUser = new CurrentUser();
     $field = array('url' => "http://www.esdev.com:81/", 'title' => "ceshi", 'userId' => 1);
     $currentUser->fromArray(array('id' => 1, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER')));
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $returnField = $this->getUserCommonAdminService()->addCommonAdmin($field);
     $this->getUserCommonAdminService()->deleteCommonAdmin($returnField['id']);
     $getCommon = $this->getUserCommonAdminService()->findCommonAdminByUserId($field['userId']);
     $this->assertNull($getCommon);
 }
 public function loadUserByUsername($username)
 {
     $user = $this->getUserService()->getUserByLoginField($username);
     if (empty($user)) {
         throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
     }
     $user['currentIp'] = $this->container->get('request')->getClientIp();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     ServiceKernel::instance()->setCurrentUser($currentUser);
     return $currentUser;
 }
Esempio n. 7
0
 /**
  * 每个testXXX执行之前,都会执行此函数,净化数据库。
  * 
  * NOTE: 如果数据库已创建,那么执行清表操作,不重建。
  */
 private function setServiceKernel()
 {
     $kernel = new \AppKernel('test', false);
     $kernel->loadClassCache();
     $kernel->boot();
     Request::enableHttpMethodParameterOverride();
     $request = Request::createFromGlobals();
     $serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug());
     $serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag());
     $serviceKernel->setConnection($kernel->getContainer()->get('database_connection'));
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 1, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_TEACHER')));
     $serviceKernel->setCurrentUser($currentUser);
     $this->serviceKernel = $serviceKernel;
 }
Esempio n. 8
0
 public function loadUserByUsername($username)
 {
     if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
         $user = $this->getUserService()->getUserByEmail($username);
     } else {
         $user = $this->getUserService()->getUserByNickname($username);
     }
     if (empty($user)) {
         throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
     }
     $user['currentIp'] = $this->container->get('request')->getClientIp();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     ServiceKernel::instance()->setCurrentUser($currentUser);
     return $currentUser;
 }
 public function uploadAction(Request $request)
 {
     $token = $request->request->get('token');
     $token = $this->getUserService()->getToken('fileupload', $token);
     if (empty($token)) {
         throw $this->createAccessDeniedException('上传TOKEN已过期或不存在。');
     }
     $user = $this->getUserService()->getUser($token['userId']);
     if (empty($user)) {
         throw $this->createAccessDeniedException('上传TOKEN非法。');
     }
     $currentUser = new CurrentUser();
     $this->getServiceKernel()->setCurrentUser($currentUser->fromArray($user));
     $originalFile = $this->get('request')->files->get('file');
     $file = $this->getCourseService()->uploadCourseFile(array(), 'local', $originalFile);
     return $this->render('TopxiaWebBundle:File:file-item.html.twig', array('file' => $file));
 }
 protected function authenticateUser($user)
 {
     $user['currentIp'] = $this->container->get('request')->getClientIp();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     ServiceKernel::instance()->setCurrentUser($currentUser);
     $token = new UsernamePasswordToken($currentUser, null, 'main', $currentUser['roles']);
     $this->container->get('security.context')->setToken($token);
     $loginEvent = new InteractiveLoginEvent($this->getRequest(), $token);
     $this->get('event_dispatcher')->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent);
     $loginBind = $this->setting('login_bind', array());
     if (empty($loginBind['login_limit'])) {
         return;
     }
     $sessionId = $this->container->get('request')->getSession()->getId();
     $this->getUserService()->rememberLoginSessionId($user['id'], $sessionId);
 }
 public function uploadAction(Request $request)
 {
     $token = $request->request->get('token');
     $token = $this->getUserService()->getToken('fileupload', $token);
     if (empty($token)) {
         throw $this->createAccessDeniedException('上传TOKEN已过期或不存在。');
     }
     $user = $this->getUserService()->getUser($token['userId']);
     if (empty($user)) {
         throw $this->createAccessDeniedException('上传TOKEN非法。');
     }
     $currentUser = new CurrentUser();
     $this->getServiceKernel()->setCurrentUser($currentUser->fromArray($user));
     $targetType = $request->query->get('targetType');
     $targetId = $request->query->get('targetId');
     $originalFile = $this->get('request')->files->get('file');
     $file = $this->getCourseService()->uploadCourseFile($targetType, $targetId, array(), 'local', $originalFile);
     return $this->createJsonResponse($file);
 }
 public function testGetData()
 {
     $user1 = $this->getUserService()->register(array('email' => '*****@*****.**', 'nickname' => 'user1', 'password' => '123456', 'confirmPassword' => '123456', 'createdIp' => '127.0.0.1'));
     $course1 = array('type' => 'normal', 'title' => 'course1');
     $course2 = array('type' => 'normal', 'title' => 'course2');
     $course3 = array('type' => 'normal', 'title' => 'course3');
     $course1 = $this->getCourseService()->createCourse($course1);
     $course2 = $this->getCourseService()->createCourse($course2);
     $course3 = $this->getCourseService()->createCourse($course3);
     $this->getCourseService()->publishCourse($course1['id']);
     $this->getCourseService()->publishCourse($course2['id']);
     $this->getCourseService()->publishCourse($course3['id']);
     $this->getCourseService()->becomeStudent($course1['id'], $user1['id']);
     $this->getCourseService()->becomeStudent($course2['id'], $user1['id']);
     $lesson1 = array('courseId' => $course1['id'], 'title' => 'lesson1', 'type' => 'text');
     $lesson2 = array('courseId' => $course1['id'], 'title' => 'lesson2', 'type' => 'text');
     $lesson3 = array('courseId' => $course2['id'], 'title' => 'lesson3', 'type' => 'text');
     $lesson1 = $this->getCourseService()->createLesson($lesson1);
     $lesson2 = $this->getCourseService()->createLesson($lesson2);
     $lesson3 = $this->getCourseService()->createLesson($lesson3);
     $this->getCourseService()->publishLesson($course1['id'], $lesson1['id']);
     $this->getCourseService()->publishLesson($course1['id'], $lesson2['id']);
     $this->getCourseService()->publishLesson($course2['id'], $lesson3['id']);
     $user = new CurrentUser();
     $user1['currentIp'] = '127.0.0.1';
     $user->fromArray($user1);
     $this->getServiceKernel()->setCurrentUser($user);
     $this->getCourseService()->startLearnLesson($course1['id'], $lesson1['id']);
     $this->getCourseService()->startLearnLesson($course1['id'], $lesson2['id']);
     $datatag = new MemberRecentlyLearnedDataTag();
     $courses = $datatag->getData(array('user' => $user));
     $this->assertEquals($course1['id'], $courses['id']);
     $this->getCourseService()->startLearnLesson($course2['id'], $lesson3['id']);
     $courses = $datatag->getData(array('user' => $user));
     $this->assertEquals($course2['id'], $courses['id']);
 }
 public function testDoPaySuccess()
 {
     $info = array('targetId' => '1', 'payment' => 'coin', 'priceType' => 'RMB', 'totalPrice' => '0.00', 'coinRate' => '1', 'coinAmount' => '0.00', 'note' => '11', 'coupon' => '123', 'couponDiscount' => '0.0');
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $textClassroom = array('title' => 'test');
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     //publish
     $processor = OrderProcessorFactory::create('classroom');
     $order = $processor->createOrder($info, array('targetId' => $classroom['id'], 'targetType' => 'classroom'));
     $result1 = $processor->doPaySuccess('success', $order);
     $result2 = $processor->doPaySuccess('', $order);
     $this->assertNull($result1);
     $this->assertNull($result2);
 }
Esempio n. 14
0
 public function initAdmin($user)
 {
     $user = $user = $this->getUserService()->register($user);
     $user['roles'] = array('ROLE_USER', 'ROLE_TEACHER', 'ROLE_SUPER_ADMIN');
     $user['currentIp'] = '127.0.0.1';
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     ServiceKernel::instance()->setCurrentUser($currentUser);
     $this->getUserService()->changeUserRoles($user['id'], array('ROLE_USER', 'ROLE_TEACHER', 'ROLE_SUPER_ADMIN'));
     return $this->getUserService()->getUser($user['id']);
 }
Esempio n. 15
0
 /**
  * 扩展API
  */
 public function testFindTeacherIds()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $textClassroom = array('title' => 'test');
     $coures = array('title' => 'coures');
     $coures = $this->getCourseService()->createCourse($coures);
     $this->getCourseService()->publishCourse($coures['id']);
     $coures = $this->getCourseService()->getCourse($coures['id']);
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     $this->getClassroomService()->updateClassroomTeachers($classroom['id']);
     $this->getClassroomService()->addCoursesToClassroom($classroom['id'], array($coures['id']));
     $classroom = $this->getClassroomService()->getClassroom($classroom['id']);
     $enabled = $this->getClassroomService()->isCourseInClassroom($coures['id'], $classroom['id']);
     $thread = array();
     $thread['title'] = 'title';
     $thread['content'] = 'xxx';
     $thread['userId'] = $user['id'];
     $thread['targetId'] = $classroom['id'];
     $thread['targetType'] = 'classroom';
     $thread['type'] = 'question';
     $Thread = $this->getThreadService()->createThread($thread);
     $this->getThreadService()->setThreadSolved($Thread['id']);
     $result = $this->getThreadService()->getThread($Thread['id']);
     $teacherId = $this->getThreadService()->findTeacherIds($Thread);
     $this->assertEquals($user['id'], $teacherId[0]);
 }
Esempio n. 16
0
 /**
  * @group current
  */
 public function testDeletePost()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => $user['id'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $user['password'], 'currentIp' => '127.0.0.1', 'roles' => $user['roles']));
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $course = $this->getCourseService()->createCourse(array('title' => 'test course'));
     $thread = array('courseId' => $course['id'], 'type' => 'discussion', 'title' => 'test thread', 'content' => 'test content');
     $createdThread = $this->getThreadService()->createThread($thread);
     $post = array('courseId' => $createdThread['courseId'], 'threadId' => $createdThread['id'], 'content' => 'post thread');
     $createdPost = $this->getThreadService()->createPost($post);
     $this->getThreadService()->deletePost($createdPost['courseId'], $createdPost['id']);
     $foundPosts = $this->getThreadService()->findThreadPosts($createdPost['courseId'], $createdPost['threadId'], 'default', 0, 20);
     $this->assertTrue(is_array($foundPosts));
     $this->assertEmpty($foundPosts);
     $thread = $this->getThreadService()->getThread($post['courseId'], $post['threadId']);
     $this->assertEquals(0, $thread['postNum']);
 }
 public function testDeleteReviewWithNotExistReview()
 {
     $this->setExpectedException('Exception');
     $user = $this->createUser();
     $user1 = $this->createStudentUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $classroom = array('title' => 'test');
     $classroom = $this->getClassroomService()->addClassroom($classroom);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     $this->getClassRoomReviewService()->deleteReview(100);
 }
Esempio n. 18
0
$loader = (require_once __DIR__ . '/../app/bootstrap.php.cache');
Debug::enable();
require_once __DIR__ . '/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$kernel->boot();
// START: init service kernel
$serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug());
$serviceKernel->setEnvVariable(array('host' => $request->getHttpHost(), 'schemeAndHost' => $request->getSchemeAndHttpHost(), 'basePath' => $request->getBasePath(), 'baseUrl' => $request->getSchemeAndHttpHost() . $request->getBasePath()));
$serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag());
$serviceKernel->registerModuleDirectory(dirname(__DIR__) . '/plugins');
$serviceKernel->setConnection($kernel->getContainer()->get('database_connection'));
$serviceKernel->getConnection()->exec('SET NAMES UTF8');
$currentUser = new CurrentUser();
$currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => $request->getClientIp(), 'roles' => array()));
$serviceKernel->setCurrentUser($currentUser);
// END: init service kernel
// NOTICE: 防止请求捕捉失败而做异常处理
// 包括:数据库连接失败等
try {
    $response = $kernel->handle($request);
} catch (\RuntimeException $e) {
    echo "Error!  " . $e->getMessage();
    die;
}
$response->send();
$kernel->terminate($request, $response);
function _fix_gpc_magic(&$item)
{
Esempio n. 19
0
 public function testdelete()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $course = array('title' => 'online test course ');
     $createCourse = $this->getCourseService()->createCourse($course);
     $result = $this->getCourseService()->getCoursesCount();
     $this->assertEquals(1, $result);
     $status = array('courseId' => $createCourse['id'], 'type' => 'start_learn_lesson', 'properties' => '{"course":{"id":"3","title":"edusoho_java\\u8bfe\\u7a0b","picture":"","type":"normal","rating":"0","about":"","price":"0.00"},"lesson":{"id":"2","number":"1","type":"text","title":"edusoho_java\\u8bfe\\u7a0b_1","summary":"124214"}}');
     $this->getStatusService()->publishStatus($status);
     $count = $this->getStatusService()->searchStatusesCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(1, $count);
     $announcementInfo = array('targetType' => 'course', 'targetId' => $createCourse['id'], 'content' => 'test_announcement', 'startTime' => time(), 'endTime' => time() + 3600 * 1000, 'url' => 'http://www.baidu.com');
     $createdAnnouncement = $this->getAnnouncementService()->createAnnouncement($announcementInfo);
     $userInfo = array('nickname' => 'test_nickname', 'password' => 'test_password', 'email' => '*****@*****.**');
     $registeredUser = $this->getUserService()->register($userInfo);
     $reviewInfo = array('title' => 'title', 'content' => 'content', 'rating' => $createCourse['rating'], 'userId' => $registeredUser['id'], 'courseId' => $createCourse['id']);
     $savedReview = $this->getReviewService()->saveReview($reviewInfo);
     $thread = array('courseId' => $createCourse['id'], 'type' => 'discussion', 'title' => 'test thread', 'content' => 'test content');
     $createdThread = $this->getThreadService()->createThread($thread);
     $lesson = $this->getCourseService()->createLesson(array('courseId' => $createCourse['id'], 'title' => 'test lesson 1', 'content' => 'test lesson content 1', 'type' => 'text'));
     $note = $this->getNoteService()->saveNote(array('content' => 'note content', 'lessonId' => $lesson['id'], 'courseId' => $createCourse['id']));
     $lessonView = array('title' => 'lessonView', 'courseId' => $createCourse['id'], 'lessonId' => $lesson['id'], 'fileId' => '1', 'fileType' => 'video', 'fileStorage' => 'local', 'fileSource' => 'www.baidu.avi');
     $this->getCourseService()->createLessonView($lessonView);
     $courseLessonReplay = array('courseId' => $createCourse['id'], 'title' => '录播回放', 'lessonId' => $lesson['id'], 'replayId' => '1', 'userId' => $currentUser['id'], 'createdTime' => time());
     $courseLessonReplay = $this->getCourseService()->addCourseLessonReplay($courseLessonReplay);
     $draft = array('userId' => 1, 'title' => 'title', 'courseId' => $createCourse['id'], 'lessonId' => $lesson['id']);
     $this->getCourseService()->createCourseDraft($draft);
     $chapter = array('courseId' => $createCourse['id'], 'title' => 'chapter 1', 'type' => 'chapter', 'number' => '1', 'seq' => '1');
     $createdChapter = $this->getCourseService()->createChapter($chapter);
     $target = 'course-' . $createCourse['id'];
     $testpaper = array('name' => 'Test', 'target' => $target, 'targetId' => $createCourse['id'], 'pattern' => 'QuestionType', 'ranges' => array('you' => 'isSB'), 'counts' => array('hello' => 'imstefanie'), 'missScores' => '-1');
     $testpaper = $this->getTestpaperService()->createTestpaper($testpaper);
     $this->assertEquals('Test', $testpaper[0]['name']);
     $question = array('type' => 'single_choice', 'stem' => 'question.', 'difficulty' => 'normal', 'answer' => array('answer'), 'target' => $target, '"stem"' => '测试', "choices" => array("爱", "测", "额", "恶"), 'uncertain' => 0, "analysis" => '', "score" => '2', "submission" => 'submit', "type" => "choice", "parentId" => 0, 'copyId' => 1, "answer" => "2");
     $question = $this->getQuestionService()->createQuestion($question);
     $testpaper = array('name' => 'Test', "description" => '测试', "limitedTime" => '0', "mode" => "rand", "range" => "course", "ranges" => array(), "counts" => array("single_choice" => "1", "choice" => "0", "uncertain_choice" => "0", "fill" => "0", "determine" => "0", "material" => "0"), 'CopyId' => 1, 'target' => $target, "scores" => array("single_choice" => "2", "uncertain_choice" => "2", "choice" => "2", "uncertain_choice" => "2", "fill" => "2", "determine" => "2", "essay" => "2", "material" => "2"), "missScores" => array("choice" => 0, "uncertain_choice" => 0), "percentages" => array("simple" => "", "normal" => "", "difficulty" => ''), "target" => $target, "pattern" => "QuestionType", "copyId" => "1");
     $testpaper = $this->getTestpaperService()->createTestpaper($testpaper);
     $this->assertEquals('Test', $testpaper[0]['name']);
     $types = array('questions', 'testpapers', 'materials', 'chapters', 'drafts', 'lessons', 'lessonLearns', 'lessonReplays', 'lessonViews', 'favorites', 'notes', 'threads', 'reviews', 'announcements', 'statuses', 'members', 'course');
     foreach ($types as $type) {
         $this->getCourseDeleteService()->delete($createCourse['id'], $type);
     }
     $questionCount = $this->getQuestionDao()->searchQuestionsCount(array('targetPrefix' => "course-{$createCourse['id']}"));
     $this->assertEquals(0, $questionCount);
     $testpaperCount = $this->getTestpaperDao()->searchTestpapersCount(array('target' => "course-{$createCourse['id']}"));
     $this->assertEquals(0, $testpaperCount);
     $materialCount = $this->getMaterialDao()->getMaterialCountByCourseId($createCourse['id']);
     $this->assertEquals(0, $materialCount);
     $chapterCount = $this->getCourseChapterDao()->searchChapterCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $chapterCount);
     $draftCount = $this->getDraftDao()->searchDraftCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $draftCount);
     $lessonCount = $this->getLessonDao()->searchLessonCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $lessonCount);
     $lessonLearnCount = $this->getLessonLearnDao()->searchLearnCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $lessonLearnCount);
     $lessonReplayCount = $this->getCourseLessonReplayDao()->searchCourseLessonReplayCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $lessonReplayCount);
     $lessonViewCount = $this->getLessonViewDao()->searchLessonViewCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $lessonViewCount);
     $favoriteCount = $this->getFavoriteDao()->searchCourseFavoriteCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $favoriteCount);
     $noteCount = $this->getCourseNoteDao()->searchNoteCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $noteCount);
     $threadCount = $this->getThreadDao()->searchThreadCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $threadCount);
     $reviewCount = $this->getReviewDao()->searchReviewsCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $reviewCount);
     $announcementCount = $this->getAnnouncementDao()->searchAnnouncementsCount(array('targetId' => $createCourse['id'], 'targetType' => 'course'));
     $this->assertEquals(0, $announcementCount);
     $statusCount = $this->getStatusDao()->searchStatusesCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $statusCount);
     $memberCount = $this->getCourseMemberDao()->searchMemberCount(array('courseId' => $createCourse['id']));
     $this->assertEquals(0, $memberCount);
 }
Esempio n. 20
0
 public function testUpdateClassroomCourses()
 {
     $teacher1 = $this->createTeacher('1');
     $teacher2 = $this->createTeacher('2');
     $teacher3 = $this->createTeacher('3');
     $teacher4 = $this->createTeacher('4');
     $teacher5 = $this->createTeacher('5');
     $teacher6 = $this->createTeacher('6');
     $teacher7 = $this->createTeacher('7');
     $teacher8 = $this->createTeacher('8');
     $textClassroom = array('title' => 'test');
     $course1 = array('title' => 'Test Course 1');
     $course2 = array('title' => 'Test Course 2');
     $course3 = array('title' => 'Test Course 3');
     $course1 = $this->getCourseService()->createCourse($course1);
     $course2 = $this->getCourseService()->createCourse($course2);
     $course3 = $this->getCourseService()->createCourse($course3);
     $this->getCourseService()->setCourseTeachers($course1['id'], array(array('id' => $teacher1['id'], 'isVisible' => 1), array('id' => $teacher2['id'], 'isVisible' => 1), array('id' => $teacher3['id'], 'isVisible' => 1)));
     $this->getCourseService()->setCourseTeachers($course2['id'], array(array('id' => $teacher4['id'], 'isVisible' => 1), array('id' => $teacher5['id'], 'isVisible' => 1)));
     $this->getCourseService()->setCourseTeachers($course3['id'], array(array('id' => $teacher1['id'], 'isVisible' => 1), array('id' => $teacher3['id'], 'isVisible' => 1), array('id' => $teacher6['id'], 'isVisible' => 1)));
     $courseIds = array($course1['id'], $course2['id'], $course3['id']);
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $classroom = $this->getClassroomService()->updateClassroom($classroom['id'], $textClassroom);
     $this->getClassroomService()->addHeadTeacher($classroom['id'], $teacher1['id']);
     $this->getClassroomService()->addCoursesToClassroom($classroom['id'], $courseIds);
     $teachers = $this->getClassroomService()->findTeachers($classroom['id']);
     $this->assertEquals(count($teachers), 6);
     $courseIds = array('6');
     $user = array();
     $user['email'] = "*****@*****.**";
     $user['nickname'] = "user";
     $user['password'] = "******";
     $user = $this->getUserService()->register($user);
     $this->getUserService()->changeUserRoles($user['id'], array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_TEACHER'));
     $user = $this->getUserService()->getUser($user['id']);
     $user = new CurrentUser();
     $user->fromArray(array('id' => 10, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_TEACHER')));
     $this->getServiceKernel()->setCurrentUser($user);
     $this->getClassroomService()->updateClassroomCourses($classroom['id'], $courseIds);
     $teachers = $this->getClassroomService()->findTeachers($classroom['id']);
     $this->assertEquals(count($teachers), 3);
 }
Esempio n. 21
0
 public function testcancelLike()
 {
     $user = $this->createCurrentUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $newArticle = $this->createArticle();
     $this->getArticleService()->like($newArticle['id']);
     $like = $this->getArticleService()->getArticleLike($newArticle['id'], $currentUser['id']);
     $this->assertNotNull($like);
     $this->getArticleService()->cancellike($newArticle['id']);
     $like = $this->getArticleService()->getArticleLike($newArticle['id'], $currentUser['id']);
     $this->assertNull($like);
 }
Esempio n. 22
0
 public function testCanOrderPay()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $payment = array('enabled' => 1, 'disabled_message' => '尚未开启支付模块,无法购买课程。', 'bank_gateway' => 'none', 'alipay_enabled' => 0, 'alipay_key' => '', 'alipay_secret' => '', 'alipay_account' => '', 'alipay_type' => 'direct', 'tenpay_enabled' => 1, 'tenpay_key' => '', 'tenpay_secret' => '');
     $this->getSettingService()->set('payment', $payment);
     $course = array('title' => 'course 1');
     $createCourse = $this->getCourseService()->createCourse($course);
     $user = $this->createNormalUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $order = $this->getOrderService()->createOrder(array('userId' => $user['id'], 'title' => "testOrder", 'targetType' => 'course', 'targetId' => $createCourse['id'], 'amount' => 10, 'payment' => 'none', 'snPrefix' => 'CR', 'status' => 'paid'));
     $result = $this->getOrderService()->canOrderPay($order);
     $this->assertEquals(1, $result);
 }
Esempio n. 23
0
 public function testExitClassroom()
 {
     $user = $this->createUser();
     $textClassroom = array('title' => 'test');
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 2, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_ADMIN')));
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => 2, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER')));
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $this->getClassroomService()->becomeStudent($classroom['id'], 2);
     $enabled = $this->getClassroomService()->canLookClassroom($classroom['id']);
     $this->assertEquals(true, $enabled);
     $this->getClassroomService()->exitClassroom($classroom['id'], 2);
     $enabled = $this->getClassroomService()->canLookClassroom($classroom['id']);
     $this->assertEquals(false, $enabled);
 }
Esempio n. 24
0
 public function testDeleteChapter()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray(array('id' => $user['id'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $user['password'], 'currentIp' => '127.0.0.1', 'roles' => $user['roles']));
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $course = $this->getCourseService()->createCourse(array('title' => 'online test course 1'));
     $chapter1 = $this->getCourseService()->createChapter(array('courseId' => $course['id'], 'title' => 'chapter 1', 'type' => 'chapter'));
     $lesson1 = $this->getCourseService()->createLesson(array('courseId' => $course['id'], 'chapterId' => $chapter1['id'], 'title' => 'test lesson 1', 'content' => 'test lesson content 1', 'type' => 'text'));
     $lesson2 = $this->getCourseService()->createLesson(array('courseId' => $course['id'], 'chapterId' => $chapter1['id'], 'title' => 'test lesson 2', 'content' => 'test lesson content 2', 'type' => 'text'));
     $chapter2 = $this->getCourseService()->createChapter(array('courseId' => $course['id'], 'title' => 'chapter 2', 'type' => 'chapter'));
     $lesson3 = $this->getCourseService()->createLesson(array('courseId' => $course['id'], 'chapterId' => $chapter2['id'], 'title' => 'test lesson 3', 'content' => 'test lesson content 3', 'type' => 'text'));
     $chapter3 = $this->getCourseService()->createChapter(array('courseId' => $course['id'], 'title' => 'chapter 3', 'type' => 'chapter'));
     $this->getCourseService()->deleteChapter($course['id'], $chapter2['id']);
     $this->assertNull($this->getCourseService()->getChapter($course['id'], $chapter2['id']));
     $lesson = $this->getCourseService()->getCourseLesson($course['id'], $lesson3['id']);
     $this->assertEquals($chapter1['id'], $lesson['chapterId']);
     // @FIXME
     // $number = 1;
     // $chapters = $this->getCourseService()->getCourseChapters($course['id']);
     // foreach ($chapters as $chapter) {
     //     $this->assertEquals($number, $chapter['number']);
     //     $number ++;
     // }
 }
Esempio n. 25
0
 public function getOrder()
 {
     $info = array('targetId' => '1', 'payment' => 'coin', 'priceType' => 'RMB', 'totalPrice' => '0.00', 'coinRate' => '1', 'coinAmount' => '0.00', 'note' => '11', 'coupon' => '123', 'couponDiscount' => '0.0');
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $textClassroom = array('title' => 'test');
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     $order = $this->getClassroomOrderService()->createOrder($info);
     $result = $this->getClassroomOrderService()->getOrder($order['id']);
     $this->assertEquals($order['status'], $result['status']);
 }
Esempio n. 26
0
 public function testCreateOrderLog()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $payment = array('enabled' => 1, 'disabled_message' => '尚未开启支付模块,无法购买课程。', 'bank_gateway' => 'none', 'alipay_enabled' => 0, 'alipay_key' => '', 'alipay_secret' => '', 'alipay_account' => '', 'alipay_type' => 'direct', 'tenpay_enabled' => 1, 'tenpay_key' => '', 'tenpay_secret' => '');
     $this->getSettingService()->set('payment', $payment);
     $course1 = array('title' => 'course 1');
     $course2 = array('title' => 'course 2');
     $createCourse1 = $this->getCourseService()->createCourse($course1);
     $createCourse2 = $this->getCourseService()->createCourse($course2);
     $user = $this->createNormalUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $order1 = array('userId' => $user['id'], 'title' => 'buy course 1', 'amount' => 1.0, 'targetType' => 'course', 'targetId' => $createCourse1['id'], 'payment' => 'tenpay');
     $order2 = array('userId' => $user['id'], 'title' => 'buy course 2', 'amount' => 10.0, 'targetType' => 'course', 'targetId' => $createCourse1['id'], 'payment' => 'alipay');
     $order1 = $this->getOrderService()->createOrder($order1);
     $order2 = $this->getOrderService()->createOrder($order2);
     $result = $this->getOrderService()->createOrderLog($order1['id'], 'ssfs');
     $this->assertEquals($result['id'], 3);
     //创建order会增加一条orderlog,这里直接增加一条Log,没有增加order
 }
Esempio n. 27
0
 public function testFindChaptersByCopyIdAndLockedCourseIds()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $course1 = array('title' => 'test one');
     $createCourse1 = $this->getCourseService()->createCourse($course1);
     $chapter1 = array('courseId' => $createCourse1['id'], 'title' => 'chapter 1', 'type' => 'chapter', 'copyId' => 1);
     $createdChapter1 = $this->getCourseService()->createChapter($chapter1);
     $chapter = $this->getCourseService()->findChaptersByCopyIdAndLockedCourseIds(1, array(1));
     $this->assertEquals('chapter 1', $chapter[0]['title']);
 }
Esempio n. 28
0
 public function testDeleteMembersByThreadId()
 {
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $Thread = $this->CreateProtecThread();
     // $user = $this->getCurrentUser();
     $fields = array('threadId' => $Thread['id'], 'userId' => $user['id'], 'nickname' => 'xiaofang');
     $member = $this->getThreadService()->createMember($fields);
     $this->assertEquals('xiaofang', $member['nickname']);
     $member = $this->getThreadService()->DeleteMembersByThreadId($Thread['id']);
     $this->assertEmpty($member);
 }