You are here

public function RedirectResourceTest::testRedirectResource in Acquia Content Hub 8.2

Tests RedirectSource event subscriber.

@dataProvider dataProviderRedirectResource

Parameters

\Acquia\ContentHubClient\CDF\CDFObject $cdf: Mock cdf data.

array $expected_source: Expected value for assert.

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/EventSubscriber/PreEntitySave/RedirectResourceTest.php, line 73

Class

RedirectResourceTest
Test that redirects are handled correctly in PreEntitySave event.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\PreEntitySave

Code

public function testRedirectResource(CDFObject $cdf, array $expected_source) {
  $redirect = Redirect::create();
  $redirect
    ->setSource('test');
  $redirect
    ->setLanguage('en');
  $redirect
    ->save();
  $event = new PreEntitySaveEvent($redirect, new DependencyStack(), $cdf);
  $this->dispatcher
    ->dispatch(AcquiaContentHubEvents::PRE_ENTITY_SAVE, $event);

  /** @var \Drupal\redirect\Entity\Redirect $entity */
  $entity = $event
    ->getEntity();
  $source = $entity
    ->getSource();
  $this
    ->assertEqual($source, $expected_source);
}