ConfigEntityTest.php 3.08 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\config\Tests\ConfigEntityTest.
6
7
8
9
10
11
12
 */

namespace Drupal\config\Tests;

use Drupal\simpletest\WebTestBase;

/**
13
 * Tests configuration entities.
14
 */
15
class ConfigEntityTest extends WebTestBase {
16

17
18
19
20
21
  /**
   * Modules to enable.
   *
   * @var array
   */
22
23
24
25
  public static $modules = array('config_test');

  public static function getInfo() {
    return array(
26
27
      'name' => 'Configuration entities',
      'description' => 'Tests configuration entities.',
28
29
30
31
32
33
34
35
      'group' => 'Configuration',
    );
  }

  /**
   * Tests basic CRUD operations through the UI.
   */
  function testCRUD() {
36
37
38
39
40
    $id = strtolower($this->randomName());
    $label1 = $this->randomName();
    $label2 = $this->randomName();
    $label3 = $this->randomName();

41
    // Create a configuration entity.
42
43
    $edit = array(
      'id' => $id,
44
      'label' => $label1,
45
46
47
    );
    $this->drupalPost('admin/structure/config_test/add', $edit, 'Save');
    $this->assertResponse(200);
48
49
    $message_insert = format_string('%label configuration has been created.', array('%label' => $label1));
    $this->assertRaw($message_insert);
50

51
    // Update the configuration entity.
52
53
    $this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
    $edit = array(
54
      'label' => $label2,
55
56
57
    );
    $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save');
    $this->assertResponse(200);
58
59
60
    $message_update = format_string('%label configuration has been updated.', array('%label' => $label2));
    $this->assertNoRaw($message_insert);
    $this->assertRaw($message_update);
61

62
    // Delete the configuration entity.
63
64
65
    $this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete');
    $this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete');
    $this->assertResponse(200);
66
67
    $this->assertNoText($label1);
    $this->assertNoText($label2);
68

69
    // Re-create a configuration entity.
70
71
    $edit = array(
      'id' => $id,
72
      'label' => $label1,
73
74
75
    );
    $this->drupalPost('admin/structure/config_test/add', $edit, 'Save');
    $this->assertResponse(200);
76
    $this->assertText($label1);
77

78
    // Rename the configuration entity's ID/machine name.
79
80
    $this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
    $edit = array(
81
      'id' => strtolower($this->randomName()),
82
      'label' => $label3,
83
84
85
    );
    $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save');
    $this->assertResponse(200);
86
87
    $this->assertNoText($label1);
    $this->assertText($label3);
88
89
90
91
92
93
94
95
96
97
98
99
100

    // Create a configuration entity with '0' machine name.
    $edit = array(
      'id' => '0',
      'label' => '0',
    );
    $this->drupalPost('admin/structure/config_test/add', $edit, 'Save');
    $this->assertResponse(200);
    $message_insert = format_string('%label configuration has been created.', array('%label' => $edit['id']));
    $this->assertRaw($message_insert);

    $this->drupalPost('admin/structure/config_test/manage/0/delete', array(), 'Delete');
    $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted');
101
  }
102

103
}