aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auth/provider_oauth_token_storage_test.php
diff options
context:
space:
mode:
authorJoseph Warner <hardolaf@hardolaf.com>2013-07-24 15:31:38 -0400
committerJoseph Warner <hardolaf@hardolaf.com>2013-07-24 15:31:54 -0400
commit0055ab7ad05258b6739f505515aaa04dd630d1cb (patch)
tree1273ec869b14f53ff652f5cdc4aa2976b1893207 /tests/auth/provider_oauth_token_storage_test.php
parent9cbf670f518b05cbb0600d20cfa30e3a9f4bd9e3 (diff)
downloadforums-0055ab7ad05258b6739f505515aaa04dd630d1cb.tar
forums-0055ab7ad05258b6739f505515aaa04dd630d1cb.tar.gz
forums-0055ab7ad05258b6739f505515aaa04dd630d1cb.tar.bz2
forums-0055ab7ad05258b6739f505515aaa04dd630d1cb.tar.xz
forums-0055ab7ad05258b6739f505515aaa04dd630d1cb.zip
[feature/oauth] Initial token storage tests
PHPBB3-11673
Diffstat (limited to 'tests/auth/provider_oauth_token_storage_test.php')
-rw-r--r--tests/auth/provider_oauth_token_storage_test.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php
new file mode 100644
index 0000000000..ba3a8a65f5
--- /dev/null
+++ b/tests/auth/provider_oauth_token_storage_test.php
@@ -0,0 +1,85 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+use OAuth\OAuth2\Token\StdOAuth2Token;
+
+class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $session_id;
+ protected $token_storage;
+ protected $user;
+
+ protected function setup()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+ $this->user = $this->getMock('phpbb_user');
+ $service_name = 'auth.provider.oauth.service.testing';
+ $token_storage_table = 'phpbb_oauth_tokens';
+
+ // Give the user a session_id that we will remember
+ $this->session_id = '12345';
+ $this->user->data['session_id'] = $this->session_id;
+
+ // Set the user id to anonymous
+ $this->user->data['user_id'] = ANONYMOUS;
+
+ $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $service_name, $token_storage_table);
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/oauth_tokens.xml');
+ }
+
+ public function test_retrieveAccessToken()
+ {
+
+ }
+
+ public function test_storeAccessToken()
+ {
+ $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') );
+ $this->token_storage->storeAccessToken($token);
+
+ // Confirm that the token is cached
+ $extraParams = $this->token_storage->retrieveAccessToken()->getExtraParams();
+ $this->assertEquals( 'param', $extraParams['extra'] );
+ $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() );
+
+ // Test that the token is stored in the database
+ $sql = 'SELECT oauth_token FROM phpbb_oauth_tokens
+ WHERE session_id = \'' . $this->session_id . '\'';
+ $result = $this->db->sql_query($sql);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ // The token is serialized before stored in the database
+ $this->assertEquals(serialize($token), $row['oauth_token']);
+ }
+
+ public function test_hasAccessToken()
+ {
+
+ }
+
+ public function test_clearToken()
+ {
+
+ }
+
+ public function test_set_user_id()
+ {
+
+ }
+} \ No newline at end of file