class TwitterProfileTest in Twitter Profile Widget 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/TwitterProfileTest.php \Drupal\Tests\twitter_profile_widget\Unit\TwitterProfileTest
- 3.x tests/src/Unit/TwitterProfileTest.php \Drupal\Tests\twitter_profile_widget\Unit\TwitterProfileTest
Tests the "TwitterProfile" service, which builds Twitter API queries.
@coversDefaultClass \Drupal\twitter_profile_widget\TwitterProfile @group twitter_profile_widget
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\twitter_profile_widget\Unit\TwitterProfileTest
Expanded class hierarchy of TwitterProfileTest
See also
Drupal\twitter_profile_widget\TwitterProfile
File
- tests/
src/ Unit/ TwitterProfileTest.php, line 16
Namespace
Drupal\Tests\twitter_profile_widget\UnitView source
class TwitterProfileTest extends UnitTestCase {
/**
* Get an accessible method using reflection.
*/
public function getAccessibleMethod($class_name, $method_name) {
$class = new \ReflectionClass($class_name);
$method = $class
->getMethod($method_name);
$method
->setAccessible(TRUE);
return $method;
}
/**
* Test TwitterProfile::buildQuery().
*
* Test that an expected Twitter REST URL for the twitter timeline returns.
* Since buildQuery() is a protected method, alter the class using reflection.
*
* @dataProvider queryDataProvider
*/
public function testQuery($config, $expected) {
// Get a reflected, accessible version of the buildQuery() method.
$protected_method = $this
->getAccessibleMethod('Drupal\\twitter_profile_widget\\TwitterProfile', 'buildQuery');
// Create a new TwitterProfile object.
$pp = new TwitterProfile();
// Use the reflection to invoke on the object.
$result = $protected_method
->invokeArgs($pp, [
$config['account'],
$config['type'],
$config['timeline'],
$config['search'],
$config['replies'],
$config['retweets'],
]);
// Make an assertion.
$this
->assertEquals($expected['url'], $result['url']);
$this
->assertEquals($expected['getfield'], $result['getfield']);
}
/**
* Data provider for testQuery().
*/
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',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
TwitterProfileTest:: |
public | function | Get an accessible method using reflection. | |
TwitterProfileTest:: |
public | function | Data provider for testQuery(). | |
TwitterProfileTest:: |
public | function | Test TwitterProfile::buildQuery(). | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |