Codebird library added
[friendica-addons.git/.git] / twitter / vendor / jublonet / codebird-php / test / setter_tests.php
1 <?php
2
3 namespace Codebird;
4 require_once ('test/codebirdt.php');
5
6 /**
7  * A Twitter library in PHP.
8  *
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
14  */
15
16 /**
17  * Setter function tests
18  *
19  * @package codebird-test
20  */
21 class Setter_Test extends \PHPUnit_Framework_TestCase
22 {
23   /**
24    * Tests setConsumerKey
25    */
26   public function testSetConsumerKey()
27   {
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'));
32   }
33
34   /**
35    * Tests setBearerToken
36    */
37   public function testSetBearerToken()
38   {
39     $cb = new CodebirdT();
40     $cb->setBearerToken('789');
41     $this->assertEquals('789', $cb->getStatic('_bearer_token'));
42   }
43
44   /**
45    * Tests getVersion
46    */
47   public function testGetVersion()
48   {
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);
53   }
54
55   /**
56    * Tests setToken
57    */
58   public function testSetToken()
59   {
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'));
64   }
65
66   /**
67    * Tests logout
68    */
69   public function testLogout()
70   {
71     $cb = new CodebirdT();
72     $cb->setToken('123', '456');
73     $cb->logout();
74     $this->assertNull($cb->get('_oauth_token'));
75     $this->assertNull($cb->get('_oauth_token_secret'));
76   }
77
78   /**
79    * Tests setUseCurl
80    */
81   public function testSetUseCurl()
82   {
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'));
90   }
91
92   /**
93    * Tests setTimeout
94    */
95   public function testSetTimeout()
96   {
97     $cb = new CodebirdT();
98     $cb->setTimeout(123);
99     $this->assertEquals(123, $cb->get('_timeouts')['request']);
100     $cb->setTimeout(0);
101     $this->assertEquals(0, $cb->get('_timeouts')['request']);
102     $cb->setTimeout(-123);
103     $this->assertEquals(0, $cb->get('_timeouts')['request']);
104   }
105
106   /**
107    * Tests setConnectionTimeout
108    */
109   public function testSetConnectionTimeout()
110   {
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']);
118   }
119
120   /**
121    * Tests setConnectionTimeout
122    */
123   public function testSetRemoteDownloadTimeout()
124   {
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']);
132   }
133
134   /**
135    * Tests setReturnFormat
136    */
137   public function testSetReturnFormat()
138   {
139     $cb = new CodebirdT();
140     $cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON);
141     $this->assertEquals($cb->get('_return_format'), CODEBIRD_RETURNFORMAT_JSON);
142   }
143
144   /**
145    * Tests setProxy
146    */
147   public function testSetProxy()
148   {
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']);
154
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']);
159   }
160
161   /**
162    * Tests setProxy
163     * @expectedException \Exception
164     * @expectedExceptionMessage Invalid proxy type specified.
165    */
166   public function testSetProxy2()
167   {
168     $cb = new CodebirdT();
169     $cb->setProxy('127.0.0.1', '8888', 1);
170   }
171
172   /**
173    * Tests setProxyAuthentication
174    */
175   public function testSetProxyAuthentication()
176   {
177     $cb = new CodebirdT();
178     $cb->setProxyAuthentication('ABCDEF');
179     $this->assertEquals('ABCDEF', $cb->get('_proxy')['authentication']);
180   }
181
182   /**
183    * Tests setStreamingCallback
184    */
185   public function testSetStreamingCallback1()
186   {
187     $callback = ['\Codebird\CodebirdT', 'streamingCallbackTest'];
188     $cb = new CodebirdT();
189     $cb->setStreamingCallback($callback);
190     $this->assertSame(
191       array_diff($callback, $cb->get('_streaming_callback')),
192       array_diff($cb->get('_streaming_callback'), $callback)
193     );
194   }
195
196   /**
197     * Tests setStreamingCallback
198     * @expectedException \Exception
199     * @expectedExceptionMessage This is not a proper callback.
200     */
201   public function testSetStreamingCallback2()
202   {
203     $cb = new CodebirdT();
204     $cb->setStreamingCallback(['\Codebird\CodebirdTX', 'somewhere']);
205   }
206
207   /**
208     * Tests getApiMethods
209     */
210   public function testGetApiMethods()
211   {
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'));
219   }
220
221   /**
222     * Tests hasProxy
223     */
224   public function testHasProxy()
225   {
226     $cb = new CodebirdT();
227     $this->assertFalse($cb->call('_hasProxy'));
228     $cb->setProxy('127.0.0.1', '8888');
229     $this->assertTrue($cb->call('_hasProxy'));
230   }
231
232   /**
233     * Tests getProxyHost
234     */
235   public function testGetProxyHost()
236   {
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'));
241   }
242
243   /**
244     * Tests getProxyPort
245     */
246   public function testGetProxyPort()
247   {
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'));
252   }
253 }