View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\PreEntitySave;
use Acquia\ContentHubClient\CDF\CDFObject;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\Event\PreEntitySaveEvent;
use Drupal\depcalc\DependencyStack;
use Drupal\KernelTests\KernelTestBase;
use Drupal\redirect\Entity\Redirect;
class RedirectResourceTest extends KernelTestBase {
public static $modules = [
'acquia_contenthub',
'depcalc',
'user',
'redirect',
'link',
'path',
'path_alias',
'field',
'system',
];
protected $dispatcher;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('field_config');
$this
->installEntitySchema('redirect');
$this
->installConfig([
'system',
]);
$this->dispatcher = $this->container
->get('event_dispatcher');
}
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);
$entity = $event
->getEntity();
$source = $entity
->getSource();
$this
->assertEqual($source, $expected_source);
}
public function dataProviderRedirectResource() {
return [
[
new CDFObject('drupal8_content_entity', 'uuid', 'date', 'date', 'uuid', [
'data' => 'eyJ1dWlkIjp7InZhbHVlIjp7ImVuIjp7InZhbHVlIjoiODE1ZDhkZmEtZDJjMi00ZmE4LTk2M2MtZWI3ZmM5YWJhMThkIn19fSwiaGFzaCI6eyJ2YWx1ZSI6eyJlbiI6IjhxX0xfY2NScmRtdUJJcWdYNTJhemNsczg1bGFIVUc3NEJLOXY4QWNVaFEifX0sInR5cGUiOnsidmFsdWUiOnsiZW4iOiJyZWRpcmVjdCJ9fSwidWlkIjp7InZhbHVlIjp7ImVuIjpbIjJiZTM1MzMyLWYyMmYtNDJiNC1hYmMwLWZkNGU2YzY2YTdjZiJdfX0sInJlZGlyZWN0X3NvdXJjZSI6eyJ2YWx1ZSI6eyJlbiI6eyJw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vbnMiOltdLCJ1cmlfdHlwZSI6ImludGVybmFsIiwiaW50ZXJuYWxfdHlwZSI6ImludGVybmFsX2VudGl0eSJ9XX19LCJzdGF0dXNfY29kZSI6eyJ2YWx1ZSI6eyJlbiI6IjMwMSJ9fSwiY3JlYXRlZCI6eyJ2YWx1ZSI6eyJlbiI6eyJ2YWx1ZSI6IjE2MjA5MDk1NTEifX19fQ==',
]),
[
'path' => 'test',
'query' => [
'topicId' => '2',
],
],
],
];
}
}