You are here

public function ShareaholicSeqShareCountsTest::testGoogleplusCountCallback in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 lib/social-share-counts/seq_share_count_test.php \ShareaholicSeqShareCountsTest::testGoogleplusCountCallback()

File

lib/social-share-counts/seq_share_count_test.php, line 82

Class

ShareaholicSeqShareCountsTest

Code

public function testGoogleplusCountCallback() {

  // given a typical google+ counts api response, test that
  // it gives back the expected result (the count which is 10)
  $json = '[{"id": "p", "result": {"kind": "pos#plusones", "id": "https://blog.shareaholic.com/", "isSetByViewer": false, "metadata": {"type": "URL", "globalCounts": {"count": 10.0}}}}]';
  $this->response['body'] = $json;
  $google_plus_count = $this->share_count
    ->google_plus_count_callback($this->response);
  $this
    ->assertEquals(10, $google_plus_count, 'It should get the correct google_plus count');

  // test when google returns unexpected json response in case they change
  $json = '{"test": "test"}';
  $this->response['body'] = $json;
  $google_plus_count = $this->share_count
    ->google_plus_count_callback($this->response);
  $this
    ->assertEquals(0, $google_plus_count, 'It should return zero google plus count for unexpected JSON');

  // test when google return non JSON response
  $json = 'hello';
  $this->response['body'] = $json;
  $google_plus_count = $this->share_count
    ->google_plus_count_callback($this->response);
  $this
    ->assertEquals(0, $google_plus_count, 'It should return zero google plus count for non JSON');
}