public function JSDelivrTest::test_getLatestVersion in Libraries CDN API 7
@covers ::getLatestVersion()
File
- tests/
src/ Plugin/ LibrariesCDN/ JSDelivrTest.php, line 247 - 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_getLatestVersion() {
// Test 1
$this->plugin
->setLibrary('ol3');
$results = array(
array(
'name' => 'ol3',
'lastversion' => '3.8.2',
),
);
$urls = $this->plugin
->getConfiguration('urls');
$url = sprintf($urls['getInformation'], $this->plugin
->getLibrary());
$this->drupal7
->shouldReceive('drupal_http_request')
->once()
->with($url, array())
->andReturn(array(
'code' => 200,
'data' => json_encode($results),
));
$this
->assertEquals('3.8.2', $this->plugin
->getLatestVersion());
// Test 2
$this->plugin
->setLibrary('ol3');
$urls = $this->plugin
->getConfiguration('urls');
$url = sprintf($urls['getInformation'], $this->plugin
->getLibrary());
$this->drupal7
->shouldReceive('drupal_http_request')
->once()
->with($url, array())
->andReturn(array(
'code' => 500,
));
$this
->assertEmpty($this->plugin
->getLatestVersion());
// Test 3
$this->plugin
->setLibrary('ol3');
$urls = $this->plugin
->getConfiguration('urls');
$url = sprintf($urls['getInformation'], $this->plugin
->getLibrary());
$this->drupal7
->shouldReceive('drupal_http_request')
->once()
->with($url, array())
->andReturn(array(
'code' => 200,
'data' => '{"name":"ol3"}',
));
$this
->assertEmpty($this->plugin
->getLatestVersion());
}