This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
forked from russpos/AWeber-API-PHP-Library
/
aweber_api.test.php
94 lines (81 loc) · 3.06 KB
/
aweber_api.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class TestAWeberAPI extends UnitTestCase {
public function setUp() {
$this->adapter = new MockOAuthAdapter();
$this->app = array(
'key' => 'RogsGzUw3QAK6cPSI24u',
'secret' => '1eaHAFJnEklS8qSBvitvSO6OCkaU4QyHU3AOE1rw',
);
$this->aweber = new AWeberAPI($this->app['key'],
$this->app['secret']);
$this->user = array(
'token' => 'lc0UcVJdlpNyVVMLzeZWZZGb61pEnlhBdHGg9usF',
'secret' => 'VMus5FW1TyX7N24xaOyc0VsylGBHC6rAomq3LM67',
);
}
/**
* App keys given at construction should be maintained internally
*/
public function test_should_contain_app_keys() {
$this->assertEqual($this->aweber->consumerKey,
$this->app['key']);
$this->assertEqual($this->aweber->consumerSecret,
$this->app['secret']);
}
/**
* OAuther adapter object should be allowed to be switched out
*/
public function test_should_allow_setting_oauth_adapter() {
$this->aweber->setAdapter($this->adapter);
$this->assertEqual($this->aweber->adapter, $this->adapter);
}
/**
* When authorization fails, an exception is raised
*/
public function test_should_raise_exception_if_auth_fails() {
MockData::$oauth = false;
$this->aweber->setAdapter($this->adapter);
try {
$account = $this->aweber->getAccount($this->user['token'],
$this->user['secret']);
$this->assertTrue(false, 'This should not run due to an exception');
}
catch (Exception $e) {
$this->assertTrue(is_a($e, 'Exception'));
}
MockData::$oauth = true;
}
# is this test a valid test?
# public function test_should_return_null_after_authorization() {
# $this->aweber->setAdapter($this->adapter);
# $account = $this->aweber->getAccount($this->user['token'],
# $this->user['secret']);
# $list = $account->lists->getById(123456);
# $this->assertTrue(empty($list));
# }
/**
* getAccount should load an AWeberEntry based on a single account
* for the authorized user
*/
public function test_getAccount() {
$this->aweber->setAdapter($this->adapter);
$account = $this->aweber->getAccount($this->user['token'],
$this->user['secret']);
$this->assertNotNull($account);
$this->assertTrue(is_a($account, 'AWeberResponse'));
$this->assertTrue(is_a($account, 'AWeberEntry'));
}
/**
* Load from URL should take a relative URL and return the correct
* object based on that request. Allows skipping around the tree
* based on URLs, not just walking it.
*/
public function test_loadFromUrl() {
$this->aweber->setAdapter($this->adapter);
$list = $this->aweber->loadFromUrl('/accounts/1/lists/303449');
$this->assertTrue(is_a($list, 'AWeberEntry'));
$this->assertEqual($list->type, 'list');
$this->assertEqual($list->id, '303449');
}
}
?>