Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 88 lines (75 sloc) 3.028 kB
db4053c First commit
Russ P authored
1 <?php
b933992 Get AWeberAPITest passing.
Jason Schadel authored
2 require_once('aweber_api/aweber_api.php');
3 require_once('mock_adapter.php');
db4053c First commit
Russ P authored
4
b933992 Get AWeberAPITest passing.
Jason Schadel authored
5 class TestAWeberAPI extends PHPUnit_Framework_TestCase {
db4053c First commit
Russ P authored
6
7 public function setUp() {
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
8 $this->adapter = get_mock_adapter();
db4053c First commit
Russ P authored
9 $this->app = array(
10 'key' => 'RogsGzUw3QAK6cPSI24u',
11 'secret' => '1eaHAFJnEklS8qSBvitvSO6OCkaU4QyHU3AOE1rw',
12 );
13 $this->aweber = new AWeberAPI($this->app['key'],
14 $this->app['secret']);
15
16 $this->user = array(
17 'token' => 'lc0UcVJdlpNyVVMLzeZWZZGb61pEnlhBdHGg9usF',
18 'secret' => 'VMus5FW1TyX7N24xaOyc0VsylGBHC6rAomq3LM67',
19 );
20 }
21
22 /**
23 * App keys given at construction should be maintained internally
24 */
25 public function test_should_contain_app_keys() {
b933992 Get AWeberAPITest passing.
Jason Schadel authored
26 $this->assertEquals($this->aweber->consumerKey, $this->app['key']);
27 $this->assertEquals($this->aweber->consumerSecret, $this->app['secret']);
db4053c First commit
Russ P authored
28 }
29
30 /**
31 * OAuther adapter object should be allowed to be switched out
32 */
33 public function test_should_allow_setting_oauth_adapter() {
34 $this->aweber->setAdapter($this->adapter);
b933992 Get AWeberAPITest passing.
Jason Schadel authored
35 $this->assertEquals($this->aweber->adapter, $this->adapter);
db4053c First commit
Russ P authored
36 }
37
38 /**
39 * When authorization fails, an exception is raised
40 */
41 public function test_should_raise_exception_if_auth_fails() {
42 MockData::$oauth = false;
43 $this->aweber->setAdapter($this->adapter);
44 try {
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
45 $account = $this->aweber->getAccount($this->user['token'], $this->user['secret']);
db4053c First commit
Russ P authored
46 $this->assertTrue(false, 'This should not run due to an exception');
47 }
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
48 catch (Exception $e) { }
db4053c First commit
Russ P authored
49 MockData::$oauth = true;
50 }
51
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
52 public function test_should_work_after_authorization() {
53 $this->aweber->setAdapter($this->adapter);
54 $account = $this->aweber->getAccount($this->user['token'], $this->user['secret']);
55 $list = $account->lists->getById(303449);
b933992 Get AWeberAPITest passing.
Jason Schadel authored
56 $this->assertEquals($list->id, 303449);
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
57 }
db4053c First commit
Russ P authored
58
59 /**
60 * getAccount should load an AWeberEntry based on a single account
61 * for the authorized user
62 */
63 public function test_getAccount() {
64 $this->aweber->setAdapter($this->adapter);
c223319 updated tests to only mock the actual request and not the request pro…
Edward F. Long, Jr authored
65 $account = $this->aweber->getAccount($this->user['token'], $this->user['secret']);
66
db4053c First commit
Russ P authored
67 $this->assertNotNull($account);
68 $this->assertTrue(is_a($account, 'AWeberResponse'));
69 $this->assertTrue(is_a($account, 'AWeberEntry'));
70 }
71
72 /**
73 * Load from URL should take a relative URL and return the correct
74 * object based on that request. Allows skipping around the tree
75 * based on URLs, not just walking it.
76 */
77 public function test_loadFromUrl() {
78 $this->aweber->setAdapter($this->adapter);
79 $list = $this->aweber->loadFromUrl('/accounts/1/lists/303449');
80
81 $this->assertTrue(is_a($list, 'AWeberEntry'));
b933992 Get AWeberAPITest passing.
Jason Schadel authored
82 $this->assertEquals($list->type, 'list');
83 $this->assertEquals($list->id, '303449');
db4053c First commit
Russ P authored
84 }
85
86 }
87 ?>
Something went wrong with that request. Please try again.