Mock_OAuthDataStore.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * A mock store for testing
  4. */
  5. class Mock_OAuthDataStore extends OAuthDataStore {
  6. private $consumer;
  7. private $request_token;
  8. private $access_token;
  9. private $nonce;
  10. function __construct() {
  11. $this->consumer = new OAuthConsumer("key", "secret", NULL);
  12. $this->request_token = new OAuthToken("requestkey", "requestsecret", 1);
  13. $this->access_token = new OAuthToken("accesskey", "accesssecret", 1);
  14. $this->nonce = "nonce";
  15. }
  16. function lookup_consumer($consumer_key) {
  17. if ($consumer_key == $this->consumer->key) return $this->consumer;
  18. return NULL;
  19. }
  20. function lookup_token($consumer, $token_type, $token) {
  21. $token_attrib = $token_type . "_token";
  22. if ($consumer->key == $this->consumer->key
  23. && $token == $this->$token_attrib->key) {
  24. return $this->$token_attrib;
  25. }
  26. return NULL;
  27. }
  28. function lookup_nonce($consumer, $token, $nonce, $timestamp) {
  29. if ($consumer->key == $this->consumer->key
  30. && (($token && $token->key == $this->request_token->key)
  31. || ($token && $token->key == $this->access_token->key))
  32. && $nonce == $this->nonce) {
  33. return $this->nonce;
  34. }
  35. return NULL;
  36. }
  37. function new_request_token($consumer, $callback = null) {
  38. if ($consumer->key == $this->consumer->key) {
  39. return $this->request_token;
  40. }
  41. return NULL;
  42. }
  43. function new_access_token($token, $consumer, $verifier = null) {
  44. if ($consumer->key == $this->consumer->key
  45. && $token->key == $this->request_token->key) {
  46. return $this->access_token;
  47. }
  48. return NULL;
  49. }
  50. }