forked from mercadolibre/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralTest.php
More file actions
139 lines (109 loc) · 3.54 KB
/
GeneralTest.php
File metadata and controls
139 lines (109 loc) · 3.54 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
require 'src/meli.php';
class FirstTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
parent::setUp();
}
protected function getMeli() {
$smMock = $this->getMock('SessionManager', array('start'));
$smMock::staticExpects($this->any())->method('start')->will($this->returnValue(0));
$meli = new Meli(array(
'appId' => 123456,
'secret' => "client secret",
'mockUrl' => "http://localhost:3000",
), $smMock);
return $meli;
}
protected function tearDown()
{
parent::tearDown();
}
public function testGetAuthUrl ()
{
$meli = $this->getMeli();
$this->assertEquals ("https://auth.mercadolibre.com.ar/authorization?client_id=123456&redirect_uri=http%3A%2F%2Fsomeurl.com&response_type=code", $meli->getLoginUrl (array('redirect_uri' => "http://someurl.com")));
}
public function testAuthorizationSuccess ()
{
$meli = $this->getMeli();
$meli->initConnect("valid code with refresh token");
$token = $meli->getAccessToken ();
$this->assertEquals ("valid token", $token['value']);
$this->assertEquals ("valid refresh token", $token['refresh_token']);
}
public function testAuthorizationFailure ()
{
$this->setExpectedException('AuthorizationException');
$meli = $this->getMeli();
$meli->initConnect("bad code");
$token = $meli->getAccessToken ();
$this->assertNull ($token['value']);
}
public function testGet ()
{
$meli = $this->getMeli();
$meli->initConnect("valid code with refresh token");
$sites = $meli->get ("/sites");
$this->assertTrue(is_array($sites));
$this->assertFalse(empty($sites));
}
public function testGetWithRefreshToken ()
{
$meli = $this->getMeli();
$meli->initConnect("expired code with refresh token");
$resp = $meli->getWithAccessToken("/users/me");
print_r($resp);
$this->assertNotNull ($resp);
}
public function testHandleErrors ()
{
$meli = $this->getMeli();
$meli->initConnect("invalid token");
$resp = $meli->getWithAccessToken("/users/me");
$this->assertEquals($resp['statusCode'], 403);
}
public function testPost ()
{
$meli = $this->getMeli();
$meli->initConnect("valid code with refresh token");
$resp = $meli->postWithAccessToken ("/items", array('foo'=>'bar'));
print_r($resp);
$this->assertEquals(201, $resp['statusCode']);
}
public function testPostWithRefreshToken ()
{
$meli = $this->getMeli();
$meli->initConnect("expired code with refresh token");
$resp = $meli->postWithAccessToken ("/items", array('foo'=>'bar'));
$this->assertEquals(201, $resp['statusCode']);
}
public function testPut ()
{
$meli = $this->getMeli();
$meli->initConnect("valid code with refresh token");
$resp = $meli -> putWithAccessToken ("/items/123", array('foo'=>'bar'));
$this->assertEquals(200, $resp['statusCode']);
}
public function testPutWithRefreshToken ()
{
$meli = $this->getMeli();
$meli->initConnect("expired code with refresh token");
$resp = $meli->putWithAccessToken ("/items/123", array('foo'=>'bar'));
$this->assertEquals(200, $resp['statusCode']);
}
public function testDelete ()
{
$meli = $this->getMeli();
$meli->initConnect("valid code with refresh token");
$resp = $meli -> deleteWithAccessToken ("/items/123");
$this->assertEquals(200, $resp['statusCode']);
}
public function testDeleteWithRefreshToken ()
{
$meli = $this->getMeli();
$meli->initConnect("expired code with refresh token");
$resp = $meli->deleteWithAccessToken ("/items/123");
$this->assertEquals(200, $resp['statusCode']);
}
}
?>