public function JSDelivrTest::test_query in Libraries CDN API 7
@covers ::query()
File
- tests/
src/ Plugin/ LibrariesCDN/ JSDelivrTest.php, line 191 - Contains \Drupal\Tests\Libraries_cdn\Plugin\LibrariesCDN\JSDelivrTest.
Class
- JSDelivrTest
- @coversDefaultClass \Drupal\libraries_cdn\Plugin\LibrariesCDN\JSDelivr
Namespace
Drupal\Tests\libraries_cdn\Plugin\LibrariesCDNCode
public function test_query() {
// Test 1
$this->plugin
->setLibrary('jquery');
$configuration = $this->plugin
->getConfiguration();
$this->drupal7
->shouldReceive('drupal_http_request')
->with(sprintf($configuration['urls']['getInformation'], $this->plugin
->getLibrary()), array())
->andReturn(array(
'code' => 200,
'data' => '{"name":"jquery"}',
));
$data = $this->plugin
->query($configuration['urls']['getInformation']);
$this
->assertEquals('jquery', $data['name']);
// Test 2
$this->plugin
->setLibrary('jquery');
$backup = $this->plugin
->getURL('getInformation');
$url = 'http://api.jsdelivr.com/fake_url?search=%s';
$this->plugin
->setURL('getInformation', $url);
$configuration = $this->plugin
->getConfiguration();
$this->drupal7
->shouldReceive('drupal_http_request')
->with(sprintf($configuration['urls']['getInformation'], $this->plugin
->getLibrary()), array())
->andReturn(array(
'code' => 404,
));
$data = $this->plugin
->query($configuration['urls']['getInformation']);
$this
->assertEmpty($data);
$this->plugin
->setURL('getInformation', $backup);
}