4 require_once ('test/codebirdt.php');
7 * A Twitter library in PHP.
9 * @package codebird-test
10 * @author Jublo Solutions <support@jublo.net>
11 * @copyright 2010-2016 Jublo Solutions <support@jublo.net>
12 * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0
13 * @link https://github.com/jublonet/codebird-php
17 * Setter function tests
19 * @package codebird-test
21 class Setter_Test extends \PHPUnit_Framework_TestCase
24 * Tests setConsumerKey
26 public function testSetConsumerKey()
28 $cb = new CodebirdT();
29 $cb->setConsumerKey('123', '456');
30 $this->assertEquals('123', $cb->getStatic('_consumer_key'));
31 $this->assertEquals('456', $cb->getStatic('_consumer_secret'));
35 * Tests setBearerToken
37 public function testSetBearerToken()
39 $cb = new CodebirdT();
40 $cb->setBearerToken('789');
41 $this->assertEquals('789', $cb->getStatic('_bearer_token'));
47 public function testGetVersion()
49 $cb = new CodebirdT();
50 $version = $cb->getVersion();
51 $this->assertEquals($version, $cb->getStatic('_version'));
52 $this->assertRegexp('/^[1-9]\d*\.\d+\.\d+(-([a-z]+\.[1-9]\d*|dev))?$/', $version);
58 public function testSetToken()
60 $cb = new CodebirdT();
61 $cb->setToken('123', '456');
62 $this->assertEquals('123', $cb->get('_oauth_token'));
63 $this->assertEquals('456', $cb->get('_oauth_token_secret'));
69 public function testLogout()
71 $cb = new CodebirdT();
72 $cb->setToken('123', '456');
74 $this->assertNull($cb->get('_oauth_token'));
75 $this->assertNull($cb->get('_oauth_token_secret'));
81 public function testSetUseCurl()
83 $cb = new CodebirdT();
84 $cb->setUseCurl(true);
85 $this->assertTrue($cb->get('_use_curl'));
86 $cb->setUseCurl(false);
87 $this->assertFalse($cb->get('_use_curl'));
88 $cb->setUseCurl('123');
89 $this->assertTrue($cb->get('_use_curl'));
95 public function testSetTimeout()
97 $cb = new CodebirdT();
99 $this->assertEquals(123, $cb->get('_timeouts')['request']);
101 $this->assertEquals(0, $cb->get('_timeouts')['request']);
102 $cb->setTimeout(-123);
103 $this->assertEquals(0, $cb->get('_timeouts')['request']);
107 * Tests setConnectionTimeout
109 public function testSetConnectionTimeout()
111 $cb = new CodebirdT();
112 $cb->setConnectionTimeout(123);
113 $this->assertEquals(123, $cb->get('_timeouts')['connect']);
114 $cb->setConnectionTimeout(0);
115 $this->assertEquals(0, $cb->get('_timeouts')['connect']);
116 $cb->setConnectionTimeout(-123);
117 $this->assertEquals(0, $cb->get('_timeouts')['connect']);
121 * Tests setConnectionTimeout
123 public function testSetRemoteDownloadTimeout()
125 $cb = new CodebirdT();
126 $cb->setRemoteDownloadTimeout(123);
127 $this->assertEquals(123, $cb->get('_timeouts')['remote']);
128 $cb->setRemoteDownloadTimeout(0);
129 $this->assertEquals(0, $cb->get('_timeouts')['remote']);
130 $cb->setRemoteDownloadTimeout(-123);
131 $this->assertEquals(0, $cb->get('_timeouts')['remote']);
135 * Tests setReturnFormat
137 public function testSetReturnFormat()
139 $cb = new CodebirdT();
140 $cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON);
141 $this->assertEquals($cb->get('_return_format'), CODEBIRD_RETURNFORMAT_JSON);
147 public function testSetProxy()
149 $cb = new CodebirdT();
150 $cb->setProxy('127.0.0.1', '8888');
151 $this->assertEquals('127.0.0.1', $cb->get('_proxy')['host']);
152 $this->assertEquals('8888', $cb->get('_proxy')['port']);
153 $this->assertEquals(CURLPROXY_HTTP, $cb->get('_proxy')['type']);
155 $cb->setProxy('127.0.0.1', '8888', CURLPROXY_SOCKS5);
156 $this->assertEquals('127.0.0.1', $cb->get('_proxy')['host']);
157 $this->assertEquals('8888', $cb->get('_proxy')['port']);
158 $this->assertEquals(CURLPROXY_SOCKS5, $cb->get('_proxy')['type']);
163 * @expectedException \Exception
164 * @expectedExceptionMessage Invalid proxy type specified.
166 public function testSetProxy2()
168 $cb = new CodebirdT();
169 $cb->setProxy('127.0.0.1', '8888', 1);
173 * Tests setProxyAuthentication
175 public function testSetProxyAuthentication()
177 $cb = new CodebirdT();
178 $cb->setProxyAuthentication('ABCDEF');
179 $this->assertEquals('ABCDEF', $cb->get('_proxy')['authentication']);
183 * Tests setStreamingCallback
185 public function testSetStreamingCallback1()
187 $callback = ['\Codebird\CodebirdT', 'streamingCallbackTest'];
188 $cb = new CodebirdT();
189 $cb->setStreamingCallback($callback);
191 array_diff($callback, $cb->get('_streaming_callback')),
192 array_diff($cb->get('_streaming_callback'), $callback)
197 * Tests setStreamingCallback
198 * @expectedException \Exception
199 * @expectedExceptionMessage This is not a proper callback.
201 public function testSetStreamingCallback2()
203 $cb = new CodebirdT();
204 $cb->setStreamingCallback(['\Codebird\CodebirdTX', 'somewhere']);
208 * Tests getApiMethods
210 public function testGetApiMethods()
212 $cb = new CodebirdT();
213 $methods = $cb->getApiMethods();
214 $this->assertArrayHasKey('GET', $cb->getStatic('_api_methods'));
215 $this->assertArrayHasKey('POST', $cb->getStatic('_api_methods'));
216 $this->assertArrayHasKey('PUT', $cb->getStatic('_api_methods'));
217 $this->assertArrayHasKey('DELETE', $cb->getStatic('_api_methods'));
218 $this->assertEquals($methods, $cb->getStatic('_api_methods'));
224 public function testHasProxy()
226 $cb = new CodebirdT();
227 $this->assertFalse($cb->call('_hasProxy'));
228 $cb->setProxy('127.0.0.1', '8888');
229 $this->assertTrue($cb->call('_hasProxy'));
235 public function testGetProxyHost()
237 $cb = new CodebirdT();
238 $this->assertNull($cb->call('_getProxyHost'));
239 $cb->setProxy('127.0.0.1', '8888');
240 $this->assertEquals('127.0.0.1', $cb->call('_getProxyHost'));
246 public function testGetProxyPort()
248 $cb = new CodebirdT();
249 $this->assertNull($cb->call('_getProxyPort'));
250 $cb->setProxy('127.0.0.1', '8888');
251 $this->assertEquals('8888', $cb->call('_getProxyPort'));