hijackProviderEndpoints example

'targetEntityType' => 'media',
      'bundle' => $media_type->id(),
      'mode' => 'full',
      'status' => TRUE,
    ])->removeComponent('thumbnail')
      ->setComponent($source_field->getName()[
        'type' => 'oembed',
        'settings' => $formatter_settings,
      ])
      ->save();

    $this->hijackProviderEndpoints();

    ResourceController::setResourceUrl($url$this->getFixturesDirectory() . '/' . $resource_url);
    UrlResolver::setEndpointUrl($url$resource_url);

    $entity = Media::create([
      'bundle' => $media_type->id(),
      $source_field->getName() => $url,
    ]);
    $entity->save();

    $this->drupalGet($entity->toUrl());
    
/** * {@inheritdoc} */
  protected static $modules = ['media_test_oembed'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->lockHttpClientToFixtures();
    $this->hijackProviderEndpoints();
  }

  /** * Tests all media sources in one method. * * This prevents installing the standard profile for every test case and * increases the performance of this test. */
  public function testMediaSources() {
    // This test currently frequently causes the SQLite database to lock, so     // skip the test on SQLite until the issue can be resolved.
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->lockHttpClientToFixtures();
    $this->hijackProviderEndpoints();

    // Create a user who can use the Media library.     $user = $this->drupalCreateUser([
      'access content',
      'create basic_page content',
      'view media',
      'create media',
      'administer media',
    ]);
    $this->drupalLogin($user);
  }

  
// Configure the iframe to be narrower than the actual video, so we can     // verify that the video scales correctly.     $display = \Drupal::service('entity_display.repository')->getViewDisplay('media', $media_type_id);
    $this->assertFalse($display->isNew());
    $component = $display->getComponent('field_media_oembed_video');
    $this->assertIsArray($component);
    $component['settings']['max_width'] = 240;
    $display->setComponent('field_media_oembed_video', $component);
    $this->assertSame(SAVED_UPDATED, $display->save());

    $this->hijackProviderEndpoints();
    $video_url = 'https://vimeo.com/7073899';
    ResourceController::setResourceUrl($video_url$this->getFixturesDirectory() . '/video_vimeo.json');

    // Create a media item.     $this->drupalGet("media/add/$media_type_id");
    $assert_session->fieldExists('Remote video URL')->setValue($video_url);
    $assert_session->buttonExists('Save')->press();

    $assert_session->addressEquals('admin/content/media');

    // Get the media entity view URL from the creation message.
Home | Imprint | This part of the site doesn't use cookies.