public function CDNJSTest::test_search in Libraries CDN API 7
@covers ::search()
File
- tests/
src/ Plugin/ LibrariesCDN/ CDNJSTest.php, line 331 - 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_search() {
// Test 1
$this->plugin
->setLibrary('jquery');
$results = array(
'results' => array(
array(
'name' => 'test1',
),
array(
'name' => 'test2',
),
array(
'name' => 'test3',
),
),
);
$urls = $this->plugin
->getConfiguration('urls');
$url = sprintf($urls['search'], $this->plugin
->getLibrary());
$this->drupal7
->shouldReceive('drupal_http_request')
->with($url, array())
->andReturn(array(
'code' => 200,
'data' => json_encode($results),
));
$data = $this->plugin
->search($this->plugin
->getLibrary());
$results = $this->plugin
->formatData('search', $results);
foreach ($data as $key => $result) {
$this
->assertEquals($results[$key]['name'], $result['name']);
}
// Test 2
$this->plugin
->setLibrary('It\'s a trap');
$urls = $this->plugin
->getConfiguration('urls');
$url = sprintf($urls['search'], $this->plugin
->getLibrary());
$this->drupal7
->shouldReceive('drupal_http_request')
->with($url, array())
->andReturn(array(
'code' => 500,
));
$data = $this->plugin
->search($this->plugin
->getLibrary());
$this
->assertEmpty($data);
}