/** * @depends testCreate */ public function testsetAsLoged() { $id = DM\Users::create(array('name' => $this->testName, 'password' => 'qq')); $this->assertTrue(is_numeric($id), 'Cant create User'); \CB\User::setAsLoged($id, 'tests_key'); $this->assertTrue(\CB\User::isLoged(), ' Error: user is not logged'); $this->assertEquals($id, $_SESSION['user']['id'], 'Sessions user is not equal with setted users'); $this->assertEquals('tests_key', $_SESSION['key'], 'Sessions key is not equal with setted keys'); }
/** * * @param type $corename */ public static function init($corename = DEFAULT_TEST_CORENAME) { $CB_PATH = \CB_DOC_ROOT; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_NAME'] = static::getHost(); $_GET['core'] = $corename; $_SESSION['user'] = array('id' => 1, 'groups' => [1]); require_once $CB_PATH . '/config.php'; require_once $CB_PATH . '/lib/language.php'; L\initTranslations(); Config::setEnvVar('user_language_index', 1); \CB\User::setAsLoged(1, 'AbrACadaBraK333y'); }
/** * @depends test_getLoginUrl */ public function test_checkLogined() { unset($_SESSION['key']); $this->assertFalse(\CB\User::isLoged(), 'ERROR checkLogined \\CB\\Users::isLoged = true'); $url = $this->getUrl(); $this->assertTrue(isset($url), 'ERROR checkLogined getGoogleLoginUrl ' . $url); $uri = parse_url($url); $Oauth2Query = []; parse_str($uri['query'], $Oauth2Query); $_GET = $Oauth2Query; $state = \CB\Oauth2Utils::decodeState($Oauth2Query['state']); $state['email'] = $this->email; $_GET['state'] = \CB\Oauth2Utils::encodeState($state); $check = \CB\Oauth2Utils::checkLogined(); $this->assertTrue($check['success'], '\\CB\\Oauth2Utils::checkLogined() return success false'); $this->assertTrue($check['user_id'] == 1, '\\CB\\Oauth2Utils::checkLogined() WRONG USER ID'); $this->assertTrue($check['session_id'] == $state['state'], '\\CB\\Oauth2Utils::checkLogined() WRON SESSION ID'); $r = \CB\User::setAsLoged($check['user_id'], $check['session_id']); $this->assertTrue($r['success'], ' User can\'t be set as logined'); }
/** * check if last notification for a user * is from userId, for objectId * @param int $userId * @param array $matches array containing properties to match with * @return bool */ protected function checkLastNotification($userId, $matches) { $rez = false; //save current user id $currentUser = $_SESSION['user']['id']; \CB\User::setAsLoged($userId, $_SESSION['key']); //$_SESSION['user']['id'] = $userId; $api = new \CB\Api\Notifications(); //check if counts are not empty $countResult = $api->getNew(array()); if ($countResult['success'] !== true || empty($countResult['data'])) { trigger_error(print_r($countResult, true), E_USER_ERROR); return $rez; } //check the last notification with given $matches $n = $this->getLastNotification($userId); if (!empty($n)) { $rez = true; foreach ($matches as $k => $v) { $rez = $rez && $n[$k] == $v; } } //restore previous user id //$_SESSION['user']['id'] = $currentUser; \CB\User::setAsLoged($currentUser, $_SESSION['key']); if (!$rez) { trigger_error(print_r($n, true), E_USER_ERROR); } return $rez; }