You are here

public function TwitterProfileTest::testQuery in Twitter Profile Widget 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/TwitterProfileTest.php \Drupal\Tests\twitter_profile_widget\Unit\TwitterProfileTest::testQuery()
  2. 3.x tests/src/Unit/TwitterProfileTest.php \Drupal\Tests\twitter_profile_widget\Unit\TwitterProfileTest::testQuery()

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

File

tests/src/Unit/TwitterProfileTest.php, line 36

Class

TwitterProfileTest
Tests the "TwitterProfile" service, which builds Twitter API queries.

Namespace

Drupal\Tests\twitter_profile_widget\Unit

Code

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']);
}