Skip to content

Commit

Permalink
Update tests to use proper AccountSid value
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Burke committed Aug 31, 2012
1 parent 0e92995 commit 37b6535
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 111 deletions.
22 changes: 11 additions & 11 deletions tests/CapabilityTest.php
Expand Up @@ -5,14 +5,14 @@
class CapabilityTest extends PHPUnit_Framework_TestCase {

public function testNoPermissions() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$payload = JWT::decode($token->generateToken(), 'foo');
$this->assertEquals($payload->iss, "AC123");
$this->assertEquals($payload->iss, "AC11111111111111111111111111111111");
$this->assertEquals($payload->scope, '');
}

public function testInboundPermissions() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientIncoming("andy");
$payload = JWT::decode($token->generateToken(), 'foo');

Expand All @@ -21,15 +21,15 @@ public function testInboundPermissions() {
}

public function testOutboundPermissions() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientOutgoing("AP123");
$payload = JWT::decode($token->generateToken(), 'foo');;
$eurl = "scope:client:outgoing?appSid=AP123";
$this->assertContains($eurl, $payload->scope);
}

public function testOutboundPermissionsParams() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientOutgoing("AP123", array("foobar" => 3));
$payload = JWT::decode($token->generateToken(), 'foo');

Expand All @@ -38,7 +38,7 @@ public function testOutboundPermissionsParams() {
}

public function testEvents() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowEventStream();
$payload = JWT::decode($token->generateToken(), 'foo');

Expand All @@ -48,7 +48,7 @@ public function testEvents() {
}

public function testEventsWithFilters() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowEventStream(array("foobar" => "hey"));
$payload = JWT::decode($token->generateToken(), 'foo');

Expand All @@ -59,7 +59,7 @@ public function testEventsWithFilters() {


public function testDecode() {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientOutgoing("AP123", array("foobar"=> 3));
$token->allowClientIncoming("andy");
$token->allowEventStream();
Expand All @@ -80,7 +80,7 @@ public function testDecode() {

function testDecodeWithAuthToken() {
try {
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$payload = JWT::decode($token->generateToken(), 'foo');
} catch (UnexpectedValueException $e) {
$this->assertTrue(false, "Could not decode with 'foo'");
Expand All @@ -89,13 +89,13 @@ function testDecodeWithAuthToken() {

function testClientNameValidation() {
$this->setExpectedException('InvalidArgumentException');
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientIncoming('@');
}

function zeroLengthNameInvalid() {
$this->setExpectedException('InvalidArgumentException');
$token = new Services_Twilio_Capability('AC123', 'foo');
$token = new Services_Twilio_Capability('AC11111111111111111111111111111111', 'foo');
$token->allowClientIncoming("");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/RequestValidatorTest.php
Expand Up @@ -45,4 +45,4 @@ function testRequestValidation() {
$this->assertTrue($validator->validate($expected, $uri, $params));
}

}
}
64 changes: 32 additions & 32 deletions tests/ResourcesTest.php
Expand Up @@ -6,13 +6,13 @@ class AvailablePhoneNumbersTest extends PHPUnit_Framework_TestCase {
function testPartialApplication() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/AvailablePhoneNumbers/US/Local.json?AreaCode=510')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/AvailablePhoneNumbers/US/Local.json?AreaCode=510')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('available_phone_numbers' => array(
'friendly_name' => '(510) 564-7903'
)))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$nums = $client->account->available_phone_numbers->getLocal('US');
$numsList = $nums->getList(array('AreaCode' => '510'));
foreach ($numsList as $num) {
Expand All @@ -23,14 +23,14 @@ function testPartialApplication() {
function testPagePhoneNumberResource() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/AvailablePhoneNumbers.json?Page=0&PageSize=50')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/AvailablePhoneNumbers.json?Page=0&PageSize=50')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
'total' => 1,
'countries' => array(array('country_code' => 'CA'))
))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$page = $client->account->available_phone_numbers->getPage('0');
$this->assertEquals('CA', $page->countries[0]->country_code);
}
Expand All @@ -47,11 +47,11 @@ function testUpdateVoiceUrl()
{
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Sandbox.json', $this->formHeaders, 'VoiceUrl=foo')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Sandbox.json', $this->formHeaders, 'VoiceUrl=foo')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('voice_url' => 'foo'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$client->account->sandbox->update('VoiceUrl', 'foo');
$this->assertEquals('foo', $client->account->sandbox->voice_url);
}
Expand All @@ -68,17 +68,17 @@ function testPost()
{
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/OutgoingCallerIds.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/OutgoingCallerIds.json',
$this->formHeaders, 'PhoneNumber=%2B14158675309&FriendlyName=My+Home+Phone+Number')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
'account_sid' => 'AC123',
'account_sid' => 'AC11111111111111111111111111111111',
'phone_number' => '+14158675309',
'friendly_name' => 'My Home Phone Number',
'validation_code' => 123456,
))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$request = $client->account->outgoing_caller_ids->create('+14158675309', array(
'FriendlyName' => 'My Home Phone Number',
));
Expand All @@ -98,12 +98,12 @@ function testPost()
{
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Applications.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Applications.json',
$this->formHeaders, 'FriendlyName=foo&VoiceUrl=bar')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'AP123'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$app = $client->account->applications->create('foo', array(
'VoiceUrl' => 'bar',
));
Expand All @@ -128,7 +128,7 @@ function testPost()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'AC345'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$account = $client->accounts->create(array(
'FriendlyName' => 'foo',
));
Expand All @@ -147,18 +147,18 @@ function testUpdateWithArray()
{
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/ConnectApps/CN123.json')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/ConnectApps/CN123.json')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'foo'))
));
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/ConnectApps/CN123.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/ConnectApps/CN123.json',
array('Content-Type' => 'application/x-www-form-urlencoded'),
'FriendlyName=Bar')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'Bar'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$cn = $client->account->connect_apps->get('CN123');
$this->assertEquals('foo', $cn->friendly_name);
$cn->update(array('FriendlyName' => 'Bar'));
Expand All @@ -169,18 +169,18 @@ function testUpdateWithOneParam()
{
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/ConnectApps/CN123.json')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/ConnectApps/CN123.json')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'foo'))
));
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/ConnectApps/CN123.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/ConnectApps/CN123.json',
array('Content-Type' => 'application/x-www-form-urlencoded'),
'FriendlyName=Bar')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'Bar'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$cn = $client->account->connect_apps->get('CN123');
$this->assertEquals('foo', $cn->friendly_name);
$cn->update('FriendlyName', 'Bar');
Expand All @@ -198,9 +198,9 @@ class NotificationTest extends PHPUnit_Framework_TestCase
function testDelete() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('delete')->once()
->with('/2010-04-01/Accounts/AC123/Notifications/NO123.json')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Notifications/NO123.json')
->andReturn(array(204, array(), ''));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$client->account->notifications->delete('NO123');
}

Expand All @@ -217,12 +217,12 @@ class SMSMessagesTest extends PHPUnit_Framework_TestCase
function testCreateMessage() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/SMS/Messages.json', $this->formHeaders,
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/SMS/Messages.json', $this->formHeaders,
'From=%2B1222&To=%2B44123&Body=Hi+there')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'SM123'))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$sms = $client->account->sms_messages->create('+1222', '+44123', 'Hi there');
$this->assertSame('SM123', $sms->sid);
}
Expand All @@ -231,15 +231,15 @@ function testBadMessageThrowsException() {
$this->setExpectedException('Services_Twilio_RestException');
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/SMS/Messages.json', $this->formHeaders,
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/SMS/Messages.json', $this->formHeaders,
'From=%2B1222&To=%2B44123&Body=' . str_repeat('hi', 81))
->andReturn(array(400, array('Content-Type' => 'application/json'),
json_encode(array(
'status' => '400',
'message' => 'Too long',
))
));
$client = new Services_Twilio('AC123', '123', null, $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', null, $http);
$sms = $client->account->sms_messages->create('+1222', '+44123',
str_repeat('hi', 81));
}
Expand Down Expand Up @@ -274,11 +274,11 @@ class MembersTest extends PHPUnit_Framework_TestCase {
function testFront() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/Front.json')
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Queues/QQ123/Members/Front.json')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$this->assertSame($firstMember->call_sid, 'CA123');
Expand All @@ -287,12 +287,12 @@ function testFront() {
function testDequeueFront() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/Front.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Queues/QQ123/Members/Front.json',
$this->formHeaders, 'Url=http%3A%2F%2Ffoo.com&Method=POST')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$firstMember->dequeue('http://foo.com');
Expand All @@ -301,12 +301,12 @@ function testDequeueFront() {
function testDequeueSid() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/CA123.json',
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Queues/QQ123/Members/CA123.json',
$this->formHeaders, 'Url=http%3A%2F%2Ffoo.com&Method=GET')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->get('CA123');
$firstMember->dequeue('http://foo.com', 'GET');
Expand All @@ -325,12 +325,12 @@ class QueuesTest extends PHPUnit_Framework_TestCase {
function testCreate() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Queues.json', $this->formHeaders,
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Queues.json', $this->formHeaders,
'FriendlyName=foo&MaxSize=123')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'QQ123', 'average_wait_time' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
$queue = $client->account->queues->create('foo',
array('MaxSize' => 123));
$this->assertSame($queue->sid, 'QQ123');
Expand Down

0 comments on commit 37b6535

Please sign in to comment.