Version 1
[yaffs-website] / web / modules / contrib / redirect / tests / src / Kernel / Migrate / d7 / PathRedirectTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\redirect\Kernel\Migrate\d7\PathRedirectTest.
6  */
7
8 namespace Drupal\Tests\redirect\Kernel\Migrate\d7;
9
10 use Drupal\redirect\Entity\Redirect;
11 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
12
13
14 /**
15  * Tests the d7_path_redirect source plugin.
16  *
17  * @group redirect
18  */
19 class PathRedirectTest extends MigrateDrupalTestBase {
20
21   /**
22    * {@inheritdoc}
23    */
24   public static $modules = array('redirect', 'link');
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31     $this->installEntitySchema('redirect');
32     $this->loadFixture(__DIR__ . '/../../../../fixtures/drupal7.php');
33
34     $this->executeMigration('d7_path_redirect');
35   }
36
37   /**
38    * Asserts various aspects of a redirect entity.
39    *
40    * @param int $id
41    *   The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
42    * @param string $source_url
43    *   The expected source url.
44    * @param string $redirect_url
45    *   The expected redirect url.
46    * @param string $status_code
47    *   The expected status code.
48    */
49   protected function assertEntity($id, $source_url, $redirect_url, $status_code) {
50     /** @var Redirect $redirect */
51     $redirect = Redirect::load($id);
52     $this->assertSame($this->getMigration('d7_path_redirect')
53       ->getIdMap()
54       ->lookupDestinationID([$id]), [$redirect->id()]);
55     $this->assertSame($source_url, $redirect->getSourceUrl());
56     $this->assertSame($redirect_url, $redirect->getRedirectUrl()
57       ->toUriString());
58     $this->assertSame($status_code, $redirect->getStatusCode());
59   }
60
61   /**
62    * Tests the Drupal 7 path redirect to Drupal 8 migration.
63    */
64   public function testPathRedirect() {
65     $this->assertEntity(5, '/test/source/url', 'base:test/redirect/url', '301');
66     $this->assertEntity(7, '/test/source/url2', 'http://test/external/redirect/url?foo=bar&biz=buz', '307');
67   }
68 }