View source
<?php
namespace Drupal\Tests\twitter_profile_widget\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\twitter_profile_widget\TwitterProfile;
class TwitterProfileTest extends UnitTestCase {
public function getAccessibleMethod($class_name, $method_name) {
$class = new \ReflectionClass($class_name);
$method = $class
->getMethod($method_name);
$method
->setAccessible(TRUE);
return $method;
}
public function testQuery($config, $expected) {
$protected_method = $this
->getAccessibleMethod('Drupal\\twitter_profile_widget\\TwitterProfile', 'buildQuery');
$pp = new TwitterProfile();
$result = $protected_method
->invokeArgs($pp, [
$config['account'],
$config['type'],
$config['timeline'],
$config['search'],
$config['replies'],
$config['retweets'],
]);
$this
->assertEquals($expected['url'], $result['url']);
$this
->assertEquals($expected['getfield'], $result['getfield']);
}
public function queryDataProvider() {
return [
[
[
'account' => 'testuser',
'type' => 'timeline',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 1,
'retweets' => 1,
],
[
'url' => 'https://api.twitter.com/1.1/lists/statuses.json',
'getfield' => '?count=10&slug=mytimeline&owner_screen_name=testuser&include_rts=1',
],
],
[
[
'account' => 'testuser',
'type' => 'timeline',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 0,
'retweets' => 0,
],
[
'url' => 'https://api.twitter.com/1.1/lists/statuses.json',
'getfield' => '?count=10&slug=mytimeline&owner_screen_name=testuser&include_rts=0&exclude_replies=1',
],
],
[
[
'account' => 'testuser',
'type' => 'search',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 1,
'retweets' => 1,
],
[
'url' => 'https://api.twitter.com/1.1/search/tweets.json',
'getfield' => '?q=search+param&count=10',
],
],
[
[
'account' => 'testuser',
'type' => 'search',
'timeline' => 'mytimeline',
'search' => '#search . param%',
'replies' => 1,
'retweets' => 1,
],
[
'url' => 'https://api.twitter.com/1.1/search/tweets.json',
'getfield' => '?q=%23search+.+param%25&count=10',
],
],
[
[
'account' => 'testuser',
'type' => 'favorites',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 1,
'retweets' => 1,
],
[
'url' => 'https://api.twitter.com/1.1/favorites/list.json',
'getfield' => '?count=10&screen_name=testuser',
],
],
[
[
'account' => 'testuser',
'type' => 'status',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 1,
'retweets' => 1,
],
[
'url' => 'https://api.twitter.com/1.1/statuses/user_timeline.json',
'getfield' => '?count=10&screen_name=testuser&include_rts=1',
],
],
[
[
'account' => 'testuser',
'type' => 'status',
'timeline' => 'mytimeline',
'search' => 'search param',
'replies' => 0,
'retweets' => 0,
],
[
'url' => 'https://api.twitter.com/1.1/statuses/user_timeline.json',
'getfield' => '?count=10&screen_name=testuser&include_rts=0&exclude_replies=1',
],
],
];
}
}