Improve oEmbed tests

Created on 23 April 2018, over 6 years ago
Updated 30 January 2023, almost 2 years ago

Problem/Motivation

#2831944: Implement media source plugin for remote video via oEmbed β†’ introduces a large new API to the Media system -- namely, support for oEmbed. This is a pretty complicated sub-API and has pretty thorough test coverage, but the tests are tricky, somewhat brittle, and hard to grok. This is because oEmbed support involves a lot of interaction with external APIs, which is hard to simulate in tests, especially functional tests.

Due to that complexity, and poor design of \Drupal\Tests\media\Traits\OEmbedTestTrait, it is all too easy to write tests which use oEmbed and only pass when they have access to the Internet. We got burned by this in #3059022: If Vimeo is down our tests break β†’ . That kind of thing is not acceptable in core; our tests need to pass in complete isolation.

Proposed resolution

Simplify OEmbedTestTrait such that the oEmbed tests are totally isolated and also easy to understand.

We can do this by relegating as much background work as possible to the media_test_oembed module. It can override relevant parts of the oEmbed system's inner workings to ensure that URLs like https://vimeo.com/123456 are "translated" to local files that are accessible via HTTP.

Meanwhile, OEmbedTestTrait will gain a new method or two, intended for use by test authors, allowing them to easily link an asset URL (such as https://www.youtube.com/watch?v=abcxyz), to a locally hosted -- yet accessible over HTTP -- fixture file, like the ones in core/modules/media/tests/fixtures/oembed/*.html. Once linked, the oEmbed system will fetch data from the local filesystem, thus ensuring that properly written oEmbed tests do not ever call out to the Internet.

Remaining tasks

  • Iterate on the patch until it's committable
  • Verify that all Media tests can pass without an Internet connection (i.e., local testing :)
  • File any relevant follow-ups and mention them in the code as needed
  • Write a change record and update any relevant deprecations
  • Commit it!

User interface changes

None.

API changes

Several methods of OEmbedTestTrait will be deprecated, and a couple new ones will be added.

Data model changes

None.

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
MediaΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.71.5 2024