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

/**
 * @file
5
 * Contains \Drupal\config\Tests\ConfigEntityStorageTest.
6 7 8 9 10 11 12 13 14 15
 */

namespace Drupal\config\Tests;

use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\Core\Config\ConfigDuplicateUUIDException;

/**
 * Tests importing config entity data when the ID or UUID matches existing data.
 */
16
class ConfigEntityStorageTest extends DrupalUnitTestBase {
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

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

  public static function getInfo() {
    return array(
      'name' => 'Configuration entity UUID conflict',
      'description' => 'Tests staging and importing config entities with IDs and UUIDs that match existing config.',
      'group' => 'Configuration',
    );
  }

  /**
   * Tests importing fields and instances with changed IDs or UUIDs.
   */
  public function testUUIDConflict() {
    $entity_type = 'config_test';
    $id = 'test_1';
    // Load the original field and instance entities.
    entity_create($entity_type, array('id' => $id))->save();
    $entity = entity_load($entity_type, $id);

43
    $original_properties = $entity->toArray();
44 45

    // Override with a new UUID and try to save.
46
    $new_uuid = $this->container->get('uuid')->generate();
47 48 49 50 51 52 53 54 55 56 57 58
    $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);
59
    $this->assertIdentical($entity->toArray(), $original_properties);
60 61 62
  }

}