You are here

public function CDNJSTest::test_getLatestVersion in Libraries CDN API 7

@covers ::getLatestVersion()

File

tests/src/Plugin/LibrariesCDN/CDNJSTest.php, line 265
Contains \Drupal\Tests\Libraries_cdn\Plugin\LibrariesCDN\CDNJSTest.

Class

CDNJSTest
@coversDefaultClass \Drupal\libraries_cdn\Plugin\LibrariesCDN\CDNJS

Namespace

Drupal\Tests\libraries_cdn\Plugin\LibrariesCDN

Code

public function test_getLatestVersion() {

  // Test 1
  $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","filename":"ol.min.js","version":"3.8.2"}',
  ));
  $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());
}