ConfigEntityStorageTest.php 1.57 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\config\Tests\ConfigEntityStorageTest.
6 7 8 9
 */

namespace Drupal\config\Tests;

10
use Drupal\simpletest\KernelTestBase;
11 12 13
use Drupal\Core\Config\ConfigDuplicateUUIDException;

/**
14 15 16 17
 * Tests staging and importing config entities with IDs and UUIDs that match
 * existing config.
 *
 * @group config
18
 */
19
class ConfigEntityStorageTest extends KernelTestBase {
20 21 22 23 24 25 26 27 28

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('config_test');

  /**
29
   * Tests creating configuration entities with changed UUIDs.
30 31 32 33
   */
  public function testUUIDConflict() {
    $entity_type = 'config_test';
    $id = 'test_1';
34
    // Load the original configuration entity.
35 36 37
    entity_create($entity_type, array('id' => $id))->save();
    $entity = entity_load($entity_type, $id);

38
    $original_properties = $entity->toArray();
39 40

    // Override with a new UUID and try to save.
41
    $new_uuid = $this->container->get('uuid')->generate();
42 43 44 45 46 47 48 49 50 51 52 53
    $entity->set('uuid', $new_uuid);

    try {
      $entity->save();
      $this->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.');
    }
    catch (ConfigDuplicateUUIDException $e) {
      $this->pass(format_string('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', array('%e' => $e)));
    }

    // Ensure that the config entity was not corrupted.
    $entity = entity_load('config_test', $entity->id(), TRUE);
54
    $this->assertIdentical($entity->toArray(), $original_properties);
55 56 57
  }

}