@@ -47,7 +47,10 @@ public function testAuthMethodCallsOauthioWithCredentialsAndCode() {
47
47
48
48
$ this ->request_mock ->expects ($ this ->once ())->method ('make_request ' )->will ($ this ->returnValue ($ response ));
49
49
50
- $ result = $ this ->oauth ->auth ('somecode ' );
50
+ $ request_object = $ this ->oauth ->auth ('some_provider ' , array (
51
+ 'code ' => 'some_code '
52
+ ));
53
+ $ result = $ request_object ->getCredentials ();
51
54
$ this ->assertEquals ($ result ['access_token ' ], 'someaccesstoken ' );
52
55
$ this ->assertEquals ($ result ['state ' ], $ this ->token );
53
56
} else {
@@ -71,7 +74,10 @@ public function testAuthMethodSetsProviderFieldInSessions() {
71
74
72
75
$ this ->request_mock ->expects ($ this ->once ())->method ('make_request ' )->will ($ this ->returnValue ($ response ));
73
76
74
- $ result = $ this ->oauth ->auth ('somecode ' );
77
+ $ request_object = $ this ->oauth ->auth ('some_provider ' , array (
78
+ 'code ' => 'somecode '
79
+ ));
80
+ $ result = $ request_object ->getCredentials ();
75
81
$ this ->assertTrue (isset ($ this ->injector ->session ['oauthio ' ]['auth ' ]['blabla ' ]));
76
82
$ this ->assertEquals ('someaccesstoken ' , $ this ->injector ->session ['oauthio ' ]['auth ' ]['blabla ' ]['access_token ' ]);
77
83
$ this ->assertEquals ($ this ->token , $ this ->injector ->session ['oauthio ' ]['auth ' ]['blabla ' ]['state ' ]);
@@ -80,4 +86,61 @@ public function testAuthMethodSetsProviderFieldInSessions() {
80
86
$ this ->fail ('OAuth::auth() does not exist ' );
81
87
}
82
88
}
89
+
90
+ public function testTokenIsRefreshedWhenCredentialsAreExpired () {
91
+ $ res = new stdClass ();
92
+ $ res ->access_token = 'someaccesstoken ' ;
93
+ $ res ->state = $ this ->token ;
94
+ $ res ->provider = 'some_provider ' ;
95
+ $ res ->refresh_token = 'some_refresh_token ' ;
96
+ $ res ->expires_in = -50 ;
97
+ $ response = new StdClass ();
98
+ $ response ->body = $ res ;
99
+
100
+ $ this ->request_mock ->expects ($ this ->exactly (3 ))->method ('make_request ' )->will ($ this ->returnValue ($ response ));
101
+
102
+ $ this ->oauth ->auth ('some_provider ' , array (
103
+ 'code ' => 'somecode '
104
+ ));
105
+
106
+ $ request_object = $ this ->oauth ->auth ('some_provider ' );
107
+
108
+ $ credentials = $ request_object ->getCredentials ();
109
+ $ this ->assertTrue ($ request_object ->wasRefreshed ());
110
+ $ this ->assertTrue ($ credentials ['refreshed ' ]);
111
+ }
112
+
113
+ public function testTokenIsRefreshedWhenForced () {
114
+ $ res = new stdClass ();
115
+ $ res ->access_token = 'someaccesstoken ' ;
116
+ $ res ->state = $ this ->token ;
117
+ $ res ->provider = 'some_provider ' ;
118
+ $ res ->refresh_token = 'some_refresh_token ' ;
119
+ $ res ->expires_in = 10000 ;
120
+ $ response = new StdClass ();
121
+ $ response ->body = $ res ;
122
+
123
+ $ this ->request_mock ->expects ($ this ->exactly (2 ))->method ('make_request ' )->will ($ this ->returnValue ($ response ));
124
+
125
+ $ this ->oauth ->auth ('some_provider ' , array (
126
+ 'code ' => 'somecode '
127
+ ));
128
+
129
+ $ res = new stdClass ();
130
+ $ res ->access_token = 'someaccesstoken ' ;
131
+ $ res ->expires_in = 3600 ;
132
+ $ res ->refresh_token = 'some_refresh_token ' ;
133
+ $ response = new StdClass ();
134
+ $ response ->body = $ res ;
135
+
136
+ $ this ->request_mock ->expects ($ this ->exactly (1 ))->method ('make_request ' )->will ($ this ->returnValue ($ response ));
137
+ $ request_object = $ this ->oauth ->auth ('some_provider ' , array (
138
+ 'force_refresh ' => true
139
+ ));
140
+
141
+ $ credentials = $ request_object ->getCredentials ();
142
+ $ this ->assertTrue ($ request_object ->wasRefreshed ());
143
+ $ this ->assertTrue ($ credentials ['refreshed ' ]);
144
+ }
145
+
83
146
}
0 commit comments