/**
  * @dataProvider userDataProvider 
  */
 public function testRegisterForContest($isGood, $who, $whom, $login, $pass, $contestID = 1, $errNo = 15)
 {
     $td = TestData::getData('userTestData');
     $req = new RegisterToContestRequest();
     $req->user = createUser($login, $pass, $whom);
     $req->contestID = $contestID;
     switch ($who) {
         case 'SuperAdmin':
             $req->sessionID = $this->sessionID;
             break;
         case 'ContestAdmin':
             $req->sessionID = $this->caConnect->sessionID;
             break;
         case 'Participant':
             $req->sessionID = $this->pConnect->sessionID;
             break;
         default:
             $req->sessionID = null;
     }
     $res = RequestSender::send($req);
     if ($isGood) {
         $this->assertEquals(new AcceptedResponse(), $res);
         $req = new ConnectToContestRequest();
         $req->login = $login;
         $req->password = $pass;
         $req->contestID = $contestID;
         $res = RequestSender::send($req);
         $this->assertNotEquals($res->sessionID, '');
         $this->assertNotEquals($res->sessionID, null);
         $this->assertEquals($res->user->login, $login);
         $this->assertEquals($res->user->userType, $whom);
     } else {
         $this->assertEquals(createFailRes($errNo), $res);
     }
 }
 /**
  * @dataProvider badLoginPassProvider 
  */
 public function testBadLoginPasswordToCreateDB($login, $pass)
 {
     $req = new CreateDataBaseRequest();
     $req->login = $login;
     $req->password = $pass;
     $this->assertEquals(createFailRes(13), RequestSender::send($req));
 }
 public function testBadAdjustUserDataRequest()
 {
     $selUserID = $this->curUsers[rand(0, sizeof($this->curUsers) - 1)]->userID;
     $badData = array(null, '', 0, array(), TestData::genUnicodeStr(rand(TestData::ALLOWED_UNICODE_LP_LENGTH + 1, TestData::MAX_LP_LENGTH)));
     $udProps = array('login', 'newType', 'password', 'userData');
     $adjUser = TestData::genUserDescription(sizeof($this->userDataColumns));
     $adjUser->{$udProps}[rand(0, sizeof($udProps) - 1)] = TestData::getRandomValue($badData);
     $req = TestData::fillRequest('AdjustUserDataRequest', array('login' => $adjUser->login, 'newType' => $adjUser->userType, 'password' => $adjUser->password, 'sessionID' => $this->sessionID, 'userData' => $adjUser->dataValue, 'userID' => $selUserID));
     $this->assertEquals(createFailRes(22), RequestSender::send($req));
 }
 public function testContestAndSuperAdminFailsToStopContest()
 {
     $req = new StopContestRequest();
     $req->sessionID = $this->sessionID;
     //TODO: add new description and code for 'This operation can be done by participant only'
     $this->assertEquals(createFailRes(42), RequestSender::send($req));
     $req->sessionID = $this->caConnect->sessionID;
     $this->assertEquals(createFailRes(42), RequestSender::send($req));
     $req->sessionID = $this->pConnect->sessionID;
     //this contest is a 'ByAdmins' contest
     $this->assertEquals(createFailRes(42), RequestSender::send($req));
 }
 public function testStartBeforeContestStarted()
 {
     $this->apiAdjustContest(array('start' => time() + 3600, 'finish' => time() + 7200));
     $td = TestData::getData('userTestData');
     $req = new ConnectToContestRequest();
     $req->login = $td['Participant'][0];
     $req->password = $td['Participant'][1];
     $req->contestID = $this->contestID;
     $res = RequestSender::send($req);
     //participant can't connect to not yet started contest
     $this->assertEquals(createFailRes(19), $res);
     $req->login = $td['ContestAdmin'][0];
     $req->password = $td['ContestAdmin'][1];
     $res = RequestSender::send($req);
     $req->contestID = $this->contestID;
     //while contest admin can
     $this->assertNotEquals($res->sessionID, '');
     $this->assertNotEquals($res->sessionID, null);
     $this->assertEquals($res->user->login, $td['ContestAdmin'][0]);
     $this->assertEquals($res->user->userType, 'ContestAdmin');
 }
 /**
  * @dataProvider disconnectionDataProvider
  */
 public function testDisconectFromContest($isGood, $who, $session_id = null)
 {
     switch ($who) {
         case 'Participant':
             $session_id = $this->pConnect->sessionID;
             break;
         case 'SuperAdmin':
             $session_id = $this->sessionID;
             break;
         case 'ContestAdmin':
             $session_id = $this->caConnect->sessionID;
             break;
     }
     $req = new DisconnectRequest();
     $req->sessionID = $session_id;
     $res = RequestSender::send($req);
     if ($isGood) {
         $this->assertEquals(new AcceptedResponse(), $res);
         $res = RequestSender::send($req);
     }
     $this->assertEquals(createFailRes(3), $res);
 }
 /**
  *@dataProvider pluginSideProvider
  */
 public function testBadContextForPluginRequests($side)
 {
     $bad = array(null, '', 0, TestData::genASCIIStr(24));
     foreach ($bad as $sessionID) {
         $req = TestData::fillRequest('AvailablePluginsRequest', array('pluginSide' => ucfirst($side), 'sessionID' => $sessionID));
         $this->assertEquals(createFailRes(239), RequestSender::send($req));
         $req = TestData::fillRequest('AdjustPluginRequest', array('sessionID' => $sessionID, 'side' => ucfirst($side), 'description' => TestData::genUnicodeStr(42), 'pluginAlias' => TestData::genFileName(12), 'pluginData' => TestData::genUnicodeStr(42)));
         $this->assertEquals(createFailRes(239), RequestSender::send($req));
         $req = TestData::fillRequest('RemovePluginRequest', array('pluginAlias' => TestData::genFileName(12), 'sessionID' => $sessionID, 'side' => ucfirst($side)));
         $this->assertEquals(createFailRes(239), RequestSender::send($req));
         $req = TestData::fillRequest('DownloadPluginRequest', array('pluginAlias' => TestData::genFileName(12), 'sessionID' => $sessionID, 'side' => ucfirst($side)));
         $this->assertEquals(createFailRes(239), RequestSender::send($req));
     }
 }
 public function testCreateContestByOtherRolesFailure()
 {
     $req = new CreateContestRequest();
     $cd = new ContestDescription();
     //contest admin failure
     $req->sessionID = $this->caConnect->sessionID;
     $req->contest = $cd;
     $this->assertEquals(createFailRes(0), RequestSender::send($req));
     //participant failure
     $req->sessionID = $this->pConnect->sessionID;
     $req->contest = $cd;
     $this->assertEquals(createFailRes(0), RequestSender::send($req));
     //null failure
     $req->sessionID = null;
     $req->contest = $cd;
     $this->assertEquals(createFailRes(0), RequestSender::send($req));
 }