public function CDNJSTest::test_query in Libraries CDN API 7
@covers ::query()
File
- tests/
src/ Plugin/ LibrariesCDN/ CDNJSTest.php, line 209 - Contains \Drupal\Tests\Libraries_cdn\Plugin\LibrariesCDN\CDNJSTest.
Class
- CDNJSTest
- @coversDefaultClass \Drupal\libraries_cdn\Plugin\LibrariesCDN\CDNJS
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.cdnjs.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);
}