/** * Test login E2E via HTTP entry point * * */ public function testNativeLoginPositiveViaHttp() { // Create an user $user = UserFactory::createUser(); // Set required context $_REQUEST['usernameOrEmail'] = $user->getUsername(); $_REQUEST['password'] = $user->getPassword(); // Turn on flag to return auth_token in response, just to validate it $_REQUEST['returnAuthToken'] = true; // Override session_start, phpunit doesn't like it, but we still validate that it is called once $this->mockSessionManager(); // Call api $_SERVER['REQUEST_URI'] = '/api/user/login'; $response = json_decode(ApiCallerMock::httpEntryPoint(), true); // Validate output $this->assertEquals('ok', $response['status']); $this->assertLogin($user, $response['auth_token']); }
/** * Tests Create User API happy path excercising the httpEntryPoint */ public function testCreateUserPositiveViahttpEntryPoint() { UserController::$permissionKey = uniqid(); // Set context $_REQUEST['username'] = Utils::CreateRandomString(); $_REQUEST['password'] = Utils::CreateRandomString(); $_REQUEST['email'] = Utils::CreateRandomString() . '@' . Utils::CreateRandomString() . '.com'; $_REQUEST['permission_key'] = UserController::$permissionKey; // Override session_start, phpunit doesn't like it, but we still validate that it is called once $this->mockSessionManager(); // Call api $_SERVER['REQUEST_URI'] = '/api/user/create'; $response = json_decode(ApiCallerMock::httpEntryPoint(), true); $this->assertEquals('ok', $response['status']); // Verify DB $user = UsersDAO::FindByUsername($_REQUEST['username']); $this->assertNotNull($user); }
/** * Tests Create User API happy path excercising the httpEntryPoint */ public function testCreateUserPositiveViahttpEntryPoint() { UserController::$permissionKey = uniqid(); // Set context $_REQUEST["username"] = Utils::CreateRandomString(); $_REQUEST["password"] = Utils::CreateRandomString(); $_REQUEST["email"] = Utils::CreateRandomString() . "@" . Utils::CreateRandomString() . ".com"; $_REQUEST["permission_key"] = UserController::$permissionKey; // Override session_start, phpunit doesn't like it, but we still validate that it is called once $this->mockSessionManager(); // Call api $_SERVER["REQUEST_URI"] = "/api/user/create"; $response = json_decode(ApiCallerMock::httpEntryPoint(), true); $this->assertEquals("ok", $response["status"]); // Verify DB $user = UsersDAO::FindByUsername($_REQUEST["username"]); $this->assertNotNull($user); }