Skip to content

Commit

Permalink
more end to end GET tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekhaled committed Apr 4, 2014
1 parent bb6ad01 commit de0ed70
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions tests/unit/endtoendTest.php
Expand Up @@ -22,13 +22,83 @@ public function _after()

public function testGet()
{
$baseUrl = $this->baseConfig['api_endpoint'] . 'v' .$this->baseConfig['api_version'];
$payload = array('foo' => 'bar');

$res = $this->V->getMe($payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($payload, $res['body']);
$this->assertSame($baseUrl . '/me/?foo=bar', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());

$res = $this->V->getMe(1, $payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($payload, $res['body']);
$this->assertSame(
$this->baseConfig['api_endpoint'] . 'v' .$this->baseConfig['api_version'] . '/me/1/?foo=bar',
$res['url']);
$this->assertSame($baseUrl . '/me/1/?foo=bar', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());

$payload = array('foo' => 'bar', 'baz' => 'foo');
$res = $this->V->getMeSomething(1, $payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($payload, $res['body']);
$this->assertSame($baseUrl . '/me/1/something?foo=bar&baz=foo', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());

$payload = array('foo' => 'bar', 'q' => '(something:else)');
$res = $this->V->getMeSomethingElse(1, $payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($payload, $res['body']);
$this->assertSame($baseUrl . '/me/1/somethingElse?foo=bar&q=(something:else)', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());

// q is properly parsed, if it's supplied as an array
$payload = array('foo' => 'bar', 'q' => array(
'a-name' => 'is_something',
'num[gt]' => 10,
'ek[eq]' => 'qwerty'
));
$res = $this->V->getMeSomethingElse(1, $payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($baseUrl . '/me/1/somethingElse?foo=bar&q=(a-name:is_something,num[gt]:10,ek[eq]:qwerty)', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());

// HATEOAS links are properly parsed
$payload = array('showLinks' => 1);
$res = $this->V->getMeSomethingElse(1, $payload);
$this->assertFalse($this->V->getError());
$this->assertSame(array(
'next' => array(
'method' => 'GET',
'uri' => 'http://someuri.com'
)
), $this->V->getLinks());

// Errors are properly caught and sent to the right class property
$payload = array('showError' => 1);
$res = $this->V->getMeSomethingElse(1, $payload);
$err = $this->V->getError();
$this->assertFalse($res);
$this->assertSame($baseUrl . '/me/1/somethingElse?showError=1', $err['url']);

//metadata is available
$payload = array('foo' => 'bar');
$res = $this->V->getMe($payload);
$this->assertSame('GET', $res['httpMethod']);
$this->assertSame($payload, $res['body']);
$this->assertSame($baseUrl . '/me/?foo=bar', $res['url']);
$this->assertFalse($this->V->getError());
$this->assertSame(array(), $this->V->getLinks());
$this->assertSame(array(
'status' => "SUCCESS",
'offset' => 0,
'count' => 20,
'total' => 21,
'links' => array()
), $this->V->getMetadata());
}
}

0 comments on commit de0ed70

Please sign in to comment.