function ProviderRepositoryTest::testCorruptProviderIgnored

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testCorruptProviderIgnored()
  2. 10 core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testCorruptProviderIgnored()

Tests a successful fetch but with a single corrupt item.

File

core/modules/media/tests/src/Unit/ProviderRepositoryTest.php, line 206

Class

ProviderRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21media%21src%21OEmbed%21ProviderRepository.php/class/ProviderRepository/11.x" title="Retrieves and caches information about oEmbed providers." class="local">\Drupal\media\OEmbed\ProviderRepository</a>

Namespace

Drupal\Tests\media\Unit

Code

public function testCorruptProviderIgnored() : void {
    $body = <<<END
[
  {
    "provider_name": "YouTube",
    "provider_url": "https:\\/\\/www.youtube.com\\/",
    "endpoints": [
      {
        "schemes": [
          "https:\\/\\/*.youtube.com\\/watch*",
          "https:\\/\\/*.youtube.com\\/v\\/*"
        ],
        "url": "https:\\/\\/www.youtube.com\\/oembed",
        "discovery": true
      }
    ]
  },
  {
    "provider_name": "Uncle Rico's football videos",
    "provider_url": "not a real url",
    "endpoints": []
  }
]
END;
    $response = new Response(200, [], $body);
    $this->responses
        ->append($response);
    // The corrupt provider should cause a warning to be logged.
    $this->logger
        ->warning("Provider Uncle Rico's football videos does not define a valid external URL.")
        ->shouldBeCalled();
    $youtube = $this->repository
        ->get('YouTube');
    // The corrupt provider should not be stored.
    $stored_data = [
        'data' => [
            'YouTube' => $youtube,
        ],
        'expires' => $this->currentTime + 604800,
    ];
    $this->assertSame($stored_data, $this->keyValue
        ->get('oembed_providers'));
    $this->expectException('InvalidArgumentException');
    $this->repository
        ->get("Uncle Rico's football videos");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.