4 require_once ('test/codebirdm.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
19 * @package codebird-test
21 class Signing_Test extends \PHPUnit_Framework_TestCase
24 * Initialise Codebird class
26 * @return \Codebird\Codebird The Codebird class
28 protected function getCB()
30 Codebird::setConsumerKey('123', '456');
31 $cb = new CodebirdM();
39 public function testUrl()
44 'q%20%2B%20b%21%22%C2%A7%24%25%26%2F%28%29%3D%3F%23%2A13%2C3%C3%A4.',
45 $cb->call('_url', ['q + b!"§$%&/()=?#*13,3ä.'])
50 'q%20%2B%20b%21%22%C2%A7%24%25%26%2F%28%29%3D%3F%23%2A13%2C3%C3%A4.',
54 'q + b!"§$%&/()=?#*13,3ä.',
63 public function testSha1()
67 'ydAlpYjrGHU7psDQ9HPgHTcwEuw=',
68 $cb->call('_sha1', ['q + b!"§$%&/()=?#*13,3ä.'])
71 // with access token secret
72 $cb->setToken('678', '789');
74 'CtivZhAHiX49ZMUuHXtKabLAuo0=',
75 $cb->call('_sha1', ['q + b!"§$%&/()=?#*13,3ä.'])
82 public function testNonce1()
88 $cb->call('_nonce', [])
93 $cb->call('_nonce', [11])
99 * @expectedException \Exception
100 * @expectedExceptionMessage Invalid nonce length.
102 public function testNonce2()
104 $cb = $this->getCB();
106 $cb->call('_nonce', [0]);
110 * Tests _getSignature
112 public function testGetSignature()
114 $cb = $this->getCB();
116 'oauth_consumer_key' => '123',
117 'oauth_nonce' => '12345678',
118 'oauth_signature_method' => 'HMAC-SHA1',
119 'oauth_timestamp' => '1400000000',
120 'oauth_token' => '567',
121 'oauth_version' => '1.0',
122 'q' => 'Test search.'
125 'ZON/m9bHvciPdtyK9BlokjeiW4M=',
126 $cb->call('_getSignature', ['GET', 'search/tweets', $base_params])
132 * @expectedException \Exception
133 * @expectedExceptionMessage To generate a signature, the consumer key must be set.
135 public function testSign1()
137 $cb = $this->getCB();
138 $cb->setConsumerKey(null, null);
139 $params = ['q' => 'Test search.'];
140 $cb->call('_sign', ['GET', 'search/tweets', $params]);
146 public function testSign2()
148 $cb = $this->getCB();
149 $params = ['q' => 'Test search.'];
151 'OAuth oauth_consumer_key="123", oauth_nonce="4247c524", oauth_signature'
152 . '="lOLNd5l6cGB9kWACxWLNKJwSD%2FI%3D", oauth_signature_method="HMAC-SHA'
153 . '1", oauth_timestamp="1412345678", oauth_version="1.0"',
154 $cb->call('_sign', ['GET', 'search/tweets', $params])
158 $cb->setToken('678', '789');
160 'OAuth oauth_consumer_key="123", oauth_nonce="4247c524", oauth_signature'
161 . '="XzegzFKEqs2PpUMym5T%2BwhEmTz4%3D", oauth_signature_method="HMAC-SHA'
162 . '1", oauth_timestamp="1412345678", oauth_token="678", oauth_version="1.0"',
163 $cb->call('_sign', ['GET', 'search/tweets', $params])