aboutsummaryrefslogtreecommitdiff
path: root/vendor/tumblr/tumblr/test
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tumblr/tumblr/test')
-rw-r--r--vendor/tumblr/tumblr/test/BlogTest.php67
-rw-r--r--vendor/tumblr/tumblr/test/PostTest.php30
-rw-r--r--vendor/tumblr/tumblr/test/RequestExceptionTest.php28
-rw-r--r--vendor/tumblr/tumblr/test/RequestHandlerTest.php71
-rw-r--r--vendor/tumblr/tumblr/test/TaggedTest.php16
-rw-r--r--vendor/tumblr/tumblr/test/TumblrTest.php51
-rw-r--r--vendor/tumblr/tumblr/test/UserTest.php40
-rw-r--r--vendor/tumblr/tumblr/test/bootstrap.php8
8 files changed, 311 insertions, 0 deletions
diff --git a/vendor/tumblr/tumblr/test/BlogTest.php b/vendor/tumblr/tumblr/test/BlogTest.php
new file mode 100644
index 0000000..22a63bf
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/BlogTest.php
@@ -0,0 +1,67 @@
+<?php
+
+class BlogTest extends TumblrTest
+{
+ public function providerCalls()
+ {
+ $test = $this; // for inner context
+
+ return array(
+
+ // getBlogInfo
+ array(function ($c) { $c->getBlogInfo('b'); }, 'GET', 'v2/blog/b.tumblr.com/info', array('api_key' => API_KEY)),
+
+ // getBlogAvatar
+ array(function ($c) use ($test) {
+ $url = $c->getBlogAvatar('b');
+ $test->assertEquals($url, 'url');
+ }, 'GET', 'v2/blog/b.tumblr.com/avatar', array('api_key' => API_KEY), 'redirect'),
+ array(function ($c) use ($test) {
+ $url = $c->getBlogAvatar('b');
+ $test->assertEquals($url, null);
+ }, 'GET', 'v2/blog/b.tumblr.com/avatar', array('api_key' => API_KEY), 'not_found'),
+ array(function ($c) { $c->getBlogAvatar('b', 128); }, 'GET', 'v2/blog/b.tumblr.com/avatar/128', array('api_key' => API_KEY)),
+
+ // getBlogLikes
+ array(function ($c) { $c->getBlogLikes('b.n'); }, 'GET', 'v2/blog/b.n/likes', array('api_key' => API_KEY)),
+ array(function ($c) { $c->getBlogLikes('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/likes', array('limit' => 10, 'api_key' => API_KEY)),
+
+ // getBlogFollowers
+ array(function ($c) { $c->getBlogFollowers('b.n'); }, 'GET', 'v2/blog/b.n/followers', null),
+ array(function ($c) { $c->getBlogFollowers('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/followers', array('limit' => 10)),
+
+ // getBlogPosts
+ array(function ($c) { $c->getBlogPosts('b.n'); }, 'GET', 'v2/blog/b.n/posts', array('api_key' => API_KEY)),
+ array(function ($c) { $c->getBlogPosts('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/posts', array('limit' => 10, 'api_key' => API_KEY)),
+ array(function ($c) { $c->getBlogPosts('b.n', array('type' => 'text')); }, 'GET', 'v2/blog/b.n/posts/text', array('api_key' => API_KEY)),
+
+ // getQueuedPosts
+ array(function ($c) { $c->getQueuedPosts('b.n'); }, 'GET', 'v2/blog/b.n/posts/queue', null),
+ array(function ($c) { $c->getQueuedPosts('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/posts/queue', array('limit' => 10)),
+
+ // getDraftPosts
+ array(function ($c) { $c->getDraftPosts('b.n'); }, 'GET', 'v2/blog/b.n/posts/draft', null),
+ array(function ($c) { $c->getDraftPosts('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/posts/draft', array('limit' => 10)),
+
+ // getSubmissionPosts
+ array(function ($c) { $c->getSubmissionPosts('b.n'); }, 'GET', 'v2/blog/b.n/posts/submission', null),
+ array(function ($c) { $c->getSubmissionPosts('b.n', array('limit' => 10)); }, 'GET', 'v2/blog/b.n/posts/submission', array('limit' => 10)),
+
+ );
+ }
+
+ public function testNotFound()
+ {
+ try {
+ $this->testCalls(function ($c) {
+ $c->getBlogInfo('b');
+ }, 'GET', 'v2/blog/b.tumblr.com/info', array('api_key' => API_KEY), 'not_found');
+ } catch (\Tumblr\API\RequestException $e) {
+ $this->assertEquals((string) $e, "Tumblr\API\RequestException: [404]: Unknown Error\n");
+
+ return;
+ }
+ $this->fail('no error thrown');
+ }
+
+}
diff --git a/vendor/tumblr/tumblr/test/PostTest.php b/vendor/tumblr/tumblr/test/PostTest.php
new file mode 100644
index 0000000..55d1bdb
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/PostTest.php
@@ -0,0 +1,30 @@
+<?php
+
+class PostTest extends TumblrTest
+{
+ public function providerCalls()
+ {
+ return array(
+
+ // delete post
+ array(function ($c) { $c->deletePost('b', 123, 'abc'); }, 'POST', 'v2/blog/b.tumblr.com/post/delete', array('id' => 123, 'reblog_key' => 'abc')),
+
+ // reblog post
+ array(function ($c) { $c->reblogPost('b', 123, 'abc'); }, 'POST', 'v2/blog/b.tumblr.com/post/reblog', array('id' => 123, 'reblog_key' => 'abc')),
+ array(function ($c) { $c->reblogPost('b', 123, 'abc', array('something' => 'else')); }, 'POST', 'v2/blog/b.tumblr.com/post/reblog', array('id' => 123, 'reblog_key' => 'abc', 'something' => 'else')),
+
+ // edit post
+ array(function ($c) { $c->editPost('b.n', 123, array('d' => 'ata')); }, 'POST', 'v2/blog/b.n/post/edit', array('d' => 'ata', 'id' => 123)),
+
+ // create post
+ array(function ($c) { $c->createPost('b.n', array('d' => 'ata')); }, 'POST', 'v2/blog/b.n/post', array('d' => 'ata')),
+
+ // single source
+ array(function ($c) { $c->createPost('b.n', array('source' => 'remote')); }, 'POST', 'v2/blog/b.n/post', array('source' => 'remote')),
+
+ // multi-source
+ array(function ($c) { $c->createPost('b.n', array('source' => array('r1', 'r2'))); }, 'POST', 'v2/blog/b.n/post', array('source[0]' => 'r1', 'source[1]' => 'r2')),
+
+ );
+ }
+}
diff --git a/vendor/tumblr/tumblr/test/RequestExceptionTest.php b/vendor/tumblr/tumblr/test/RequestExceptionTest.php
new file mode 100644
index 0000000..6180bca
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/RequestExceptionTest.php
@@ -0,0 +1,28 @@
+<?php
+
+class RequestExceptionTest extends PHPUnit_Framework_TestCase
+{
+ public function provider()
+ {
+ $class_name = 'Tumblr\API\RequestException';
+
+ return array(
+
+ array(array('status' => 401, 'body' => '{}'), "$class_name: [401]: Unknown Error\n"),
+
+ array(array('status' => 404, 'body' => '{"meta":{"msg":"cool story bro"}}'), "$class_name: [404]: cool story bro\n"),
+
+ );
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function testErrorString($responseArr, $expectedString)
+ {
+ $response = (object) $responseArr;
+ $err = new \Tumblr\API\RequestException($response);
+ $this->assertEquals((string) $err, $expectedString);
+ }
+
+}
diff --git a/vendor/tumblr/tumblr/test/RequestHandlerTest.php b/vendor/tumblr/tumblr/test/RequestHandlerTest.php
new file mode 100644
index 0000000..4dfdcb9
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/RequestHandlerTest.php
@@ -0,0 +1,71 @@
+<?php
+
+class RequestHandlerTest extends \PHPUnit_Framework_TestCase
+{
+ public function testBaseUrlHasTrailingSlash()
+ {
+ $client = new Tumblr\API\Client(API_KEY);
+ $rh = $client->getRequestHandler();
+ $this->assertInstanceOf('Tumblr\API\RequestHandler', $rh);
+
+ $rh->setBaseUrl('http://example.com');
+ $this->assertAttributeEquals('http://example.com/', 'baseUrl', $rh);
+
+ $rh->setBaseUrl('http://example.com/');
+ $this->assertAttributeEquals('http://example.com/', 'baseUrl', $rh);
+ }
+
+ /**
+ * @expectedException GuzzleHttp\Exception\ConnectException
+ */
+ public function testRequestThrowsErrorOnMalformedBaseUrl()
+ {
+ $client = new Tumblr\API\Client(API_KEY);
+ $rh = $client->getRequestHandler();
+ $rh->setBaseUrl('this is a malformed URL!');
+
+ $options = array('some kinda option');
+
+ $rh->request('GET', 'foo', $options);
+
+ }
+
+ /**
+ * @expectedException Tumblr\API\RequestException
+ * @expectedExceptionCode 400
+ * @expectedExceptionMessage Sadface
+ */
+ public function testRequestThrowsOnBadResponse()
+ {
+ // Setup mock handler and response
+ $mock = new GuzzleHttp\Handler\MockHandler([
+ new GuzzleHttp\Psr7\Response(400, [], '{"meta": {"status": 400, "msg": "Sadface"} }'),
+ ]);
+ $stack = GuzzleHttp\HandlerStack::create($mock);
+ $guzzle = new GuzzleHttp\Client(['handler' => $stack]);
+
+ // Attached mocked guzzle client
+ $client = new Tumblr\API\Client(API_KEY);
+ $client->getRequestHandler()->client = $guzzle;
+
+ // Throws because it got a 400 back
+ $client->getBlogInfo('ceyko.tumblr.com');
+ }
+
+ public function testRequestGetsJsonResponseField()
+ {
+ // Setup mock handler and response
+ $mock = new GuzzleHttp\Handler\MockHandler([
+ new GuzzleHttp\Psr7\Response(200, [], '{"meta": {"status": 200, "msg": "OK"}, "response": "Response Text"}'),
+ ]);
+ $stack = GuzzleHttp\HandlerStack::create($mock);
+ $guzzle = new GuzzleHttp\Client(['handler' => $stack]);
+
+ // Attached mocked guzzle client
+ $client = new Tumblr\API\Client(API_KEY);
+ $client->getRequestHandler()->client = $guzzle;
+
+ // Parses out the `reponse` field in json on success
+ $this->assertEquals($client->getBlogInfo('ceyko.tumblr.com'), 'Response Text');
+ }
+}
diff --git a/vendor/tumblr/tumblr/test/TaggedTest.php b/vendor/tumblr/tumblr/test/TaggedTest.php
new file mode 100644
index 0000000..c595508
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/TaggedTest.php
@@ -0,0 +1,16 @@
+<?php
+
+class TaggedTest extends TumblrTest
+{
+ public function providerCalls()
+ {
+ return array(
+
+ // getTaggedPosts
+ array(function ($c) { $c->getTaggedPosts('hey'); }, 'GET', 'v2/tagged', array('tag' => 'hey', 'api_key' => API_KEY)),
+ array(function ($c) { $c->getTaggedPosts('hey', array('limit' => 10)); }, 'GET', 'v2/tagged', array('limit' => 10, 'tag' => 'hey', 'api_key' => API_KEY)),
+
+ );
+ }
+
+}
diff --git a/vendor/tumblr/tumblr/test/TumblrTest.php b/vendor/tumblr/tumblr/test/TumblrTest.php
new file mode 100644
index 0000000..a014634
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/TumblrTest.php
@@ -0,0 +1,51 @@
+<?php
+
+class TumblrTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider providerCalls
+ */
+ public function testCalls($callable, $type, $path, $params, $which_mock = 'perfect')
+ {
+ // a good response
+ $response = $this->getResponseMock($which_mock);
+
+ // Create request mock and set it to check for the proper response
+ $request = $this->getMock('Tumblr\API\RequestHandler', array('request'));
+ $request->expects($this->once())
+ ->method('request')
+ ->with($this->equalTo($type), $this->equalTo($path), $this->equalTo($params))
+ ->will($this->returnValue($response));
+
+ // Create a new client and set it up to use that request handler
+ $client = new Tumblr\API\Client(API_KEY);
+ $ref = new ReflectionObject($client);
+ $prop = $ref->getProperty('requestHandler');
+ $prop->setAccessible(true);
+ $prop->setValue($client, $request);
+
+ // Give it tokens
+ $client->setToken('t1', 't2');
+
+ // And then run the callback to check the results
+ $callable($client);
+ }
+
+ private function getResponseMock($which)
+ {
+ $response = new stdClass;
+ if ($which == 'perfect') {
+ $response->status = 200;
+ $response->body = '{"response":[]}';
+ } elseif ($which == 'redirect') {
+ $response->status = 301;
+ $response->headers = array('Location' => array('url'));
+ } elseif ($which == 'not_found') {
+ $response->status = 404;
+ $response->body = '{}';
+ }
+
+ return $response;
+ }
+
+}
diff --git a/vendor/tumblr/tumblr/test/UserTest.php b/vendor/tumblr/tumblr/test/UserTest.php
new file mode 100644
index 0000000..e42b336
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/UserTest.php
@@ -0,0 +1,40 @@
+<?php
+
+class UserTest extends TumblrTest
+{
+ public function providerCalls()
+ {
+ return array(
+
+ // getUserInfo
+ array(function ($c) { $c->getUserInfo(); }, 'GET', 'v2/user/info', null),
+
+ // getDashboardPosts
+ array(function ($c) { $c->getDashboardPosts(); }, 'GET', 'v2/user/dashboard', null),
+ array(function ($c) { $c->getDashboardPosts(array('limit' => 10)); }, 'GET', 'v2/user/dashboard', array('limit' => 10)),
+
+ // getFollowedBlogs
+ array(function ($c) { $c->getFollowedBlogs(); }, 'GET', 'v2/user/following', null),
+ array(function ($c) { $c->getFollowedBlogs(array('limit' => 10)); }, 'GET', 'v2/user/following', array('limit' => 10)),
+
+ // getLikedPosts
+ array(function ($c) { $c->getLikedPosts(); }, 'GET', 'v2/user/likes', null),
+ array(function ($c) { $c->getLikedPosts(array('limit' => 10)); }, 'GET', 'v2/user/likes', array('limit' => 10)),
+
+ // follow
+ array(function ($c) { $c->follow('b'); }, 'POST', 'v2/user/follow', array('url' => 'b.tumblr.com')),
+ array(function ($c) { $c->follow('b.n'); }, 'POST', 'v2/user/follow', array('url' => 'b.n')),
+
+ // unfollow
+ array(function ($c) { $c->unfollow('b'); }, 'POST', 'v2/user/unfollow', array('url' => 'b.tumblr.com')),
+
+ // like
+ array(function ($c) { $c->like(123, 'abc'); }, 'POST', 'v2/user/like', array('id' => 123, 'reblog_key' => 'abc')),
+
+ // unlike
+ array(function ($c) { $c->unlike(123, 'abc'); }, 'POST', 'v2/user/unlike', array('id' => 123, 'reblog_key' => 'abc')),
+
+ );
+ }
+
+}
diff --git a/vendor/tumblr/tumblr/test/bootstrap.php b/vendor/tumblr/tumblr/test/bootstrap.php
new file mode 100644
index 0000000..cfa1b00
--- /dev/null
+++ b/vendor/tumblr/tumblr/test/bootstrap.php
@@ -0,0 +1,8 @@
+<?php
+
+date_default_timezone_set('America/New_York');
+
+require_once 'vendor/autoload.php';
+require_once 'test/TumblrTest.php';
+
+define('API_KEY', 'the testing consumer key');