Project

General

Profile

Paste
Download (8.08 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / ctools / tests / ctools_export_test / ctools_export.test @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * Tests for the CTools export system.
5
 */
6
class CtoolsExportCrudTestCase extends DrupalWebTestCase {
7

    
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'Export CRUD',
14
      'description' => 'Test the CRUD functionality for the ctools export system.',
15
      'group' => 'ctools',
16
    );
17
  }
18

    
19
  /**
20
   * {@inheritdoc}
21
   */
22
  public function setUp(array $modules = array()) {
23
    $modules[] = 'ctools';
24
    $modules[] = 'ctools_export_test';
25
    parent::setUp($modules);
26
  }
27

    
28
  /**
29
   * Tests CRUD operation: Load.
30
   */
31
  public function testCrudExportLoad() {
32
    $loaded_export = ctools_export_crud_load('ctools_export_test', 'database_test');
33

    
34
    $expected_export = new stdClass();
35
    $expected_export->machine = 'database_test';
36
    $expected_export->title = 'Database test';
37
    $expected_export->number = 0;
38
    $expected_export->data = array(
39
      'test_1' => 'Test 1',
40
      'test_2' => 'Test 2',
41
    );
42
    $expected_export->table = 'ctools_export_test';
43
    $expected_export->export_type = EXPORT_IN_DATABASE;
44
    $expected_export->type = 'Normal';
45

    
46
    $this->assertEqual($expected_export, $loaded_export, 'An exportable object has been loaded correctly from the database.');
47
  }
48

    
49
  /**
50
   * Tests CRUD operation: Load multiple.
51
   */
52
  public function testCrudExportLoadMultiple() {
53
    $exportable_names = array('database_test', 'overridden_test', 'default_test');
54
    $loaded_exports = ctools_export_crud_load_multiple('ctools_export_test', $exportable_names);
55

    
56
    $this->assertEqual(count($loaded_exports), 3, 'All exportables have been loaded.');
57
  }
58

    
59
  /**
60
   * Tests CRUD operation: Load all.
61
   */
62
  public function testCrudExportLoadAll() {
63
    $loaded_exports = ctools_export_crud_load_all('ctools_export_test');
64

    
65
    $this->assertEqual(count($loaded_exports), 3, 'All exportables have been loaded.');
66
  }
67

    
68
  /**
69
   * Tests CRUD operation: Save.
70
   */
71
  public function testCrudExportSave() {
72
    $default_export = ctools_export_crud_load('ctools_export_test', 'default_test');
73

    
74
    $this->assertTrue($default_export->in_code_only, 'The loaded exportable is in code only.');
75

    
76
    ctools_export_crud_save('ctools_export_test', $default_export);
77

    
78
    // Clear the static cache.
79
    ctools_export_load_object_reset('ctools_export_test');
80

    
81
    $overridden_export = ctools_export_crud_load('ctools_export_test', 'default_test');
82

    
83
    $this->assertTrue($overridden_export->export_type === 3, 'The loaded exportable is overridden in the database.');
84
  }
85

    
86
  /**
87
   * Tests CRUD operation: New.
88
   */
89
  public function testCrudExportNew() {
90
    // Default exportable with defualt values.
91
    $new_export = ctools_export_crud_new('ctools_export_test');
92

    
93
    $expected_export = new stdClass();
94
    $expected_export->machine = '';
95
    $expected_export->title = '';
96
    $expected_export->number = 0;
97
    $expected_export->data = NULL;
98
    $expected_export->export_type = NULL;
99
    $expected_export->type = 'Local';
100

    
101
    $this->assertEqual($expected_export, $new_export, 'An exportable with default values is created.');
102

    
103
    // Default exportable without default values.
104
    $new_export = ctools_export_crud_new('ctools_export_test', FALSE);
105

    
106
    $expected_export = new stdClass();
107
    $expected_export->machine = '';
108
    $expected_export->title = '';
109
    $expected_export->number = NULL;
110
    $expected_export->data = NULL;
111

    
112
    $this->assertEqual($expected_export, $new_export, 'An exportable without default values has been created.');
113
  }
114

    
115
  /**
116
   * Tests CRUD operation: Revert.
117
   */
118
  public function testCrudExportRevert() {
119
    // Load exportable, will come from database.
120
    $original_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
121

    
122
    $this->assertTrue($original_export->export_type === 3, 'Loaded export is overridden.');
123

    
124
    $machine = $original_export->machine;
125
    ctools_export_crud_delete('ctools_export_test', $original_export);
126

    
127
    $result = db_query("SELECT machine FROM {ctools_export_test} WHERE machine = :machine", array(':machine' => $machine))->fetchField();
128

    
129
    $this->assertFalse($result, 'The exportable object has been removed from the database.');
130

    
131
    // Clear the static cache.
132
    ctools_export_load_object_reset('ctools_export_test');
133

    
134
    // Reload the same object.
135
    $default_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
136

    
137
    // Check the exportable is now in_code_only.
138
    $this->assertTrue($default_export->in_code_only, 'The loaded exportable is in the database only.');
139

    
140
    // Make sure the default object loaded matches the same overridden one in
141
    // the database.
142
    $this->assertEqual($original_export->machine, $default_export->machine, 'The default exportable has been loaded and matches the overridden exportable.');
143
  }
144

    
145
  /**
146
   * Tests CRUD operation: Delete.
147
   */
148
  public function testCrudExportDelete() {
149
    // Create a stub entry save it and delete it from the database.
150
    $new_export = ctools_export_crud_new('ctools_export_test');
151
    ctools_export_crud_save('ctools_export_test', $new_export);
152

    
153
    $machine = $new_export->machine;
154
    ctools_export_crud_delete('ctools_export_test', $new_export);
155
    $result = ctools_export_crud_load('ctools_export_test', $machine);
156

    
157
    $this->assertFalse($result, 'The new exportable has been removed from the database.');
158

    
159
    // Load the database only exportable.
160
    $database_export = ctools_export_crud_load('ctools_export_test', 'database_test');
161

    
162
    $machine = $database_export->machine;
163
    ctools_export_crud_delete('ctools_export_test', $database_export);
164

    
165
    // Clear the exportable caches as it's been loaded above.
166
    ctools_export_load_object_reset('ctools_export_test');
167
    $result = ctools_export_crud_load('ctools_export_test', $machine);
168

    
169
    $this->assertFalse($result, 'The database exportable has been removed from the database.');
170
  }
171

    
172
  /**
173
   * Tests CRUD operation: Set status.
174
   */
175
  public function testCrudExportSetStatus() {
176
    // Database only object.
177
    $database_export = ctools_export_crud_load('ctools_export_test', 'database_test');
178
    ctools_export_crud_disable('ctools_export_test', $database_export);
179
    ctools_export_load_object_reset('ctools_export_test');
180
    $disabled_export = ctools_export_crud_load('ctools_export_test', 'database_test');
181

    
182
    $this->assertTrue($disabled_export->disabled, 'The database only exportable has been disabled.');
183

    
184
    ctools_export_crud_enable('ctools_export_test', $disabled_export);
185
    ctools_export_load_object_reset('ctools_export_test');
186
    $enabled_export = ctools_export_crud_load('ctools_export_test', 'database_test');
187

    
188
    $this->assertTrue(empty($enabled_export->disabled), 'The database only exportable has been enabled.');
189

    
190
    // Overridden object.
191
    $overridden_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
192
    ctools_export_crud_disable('ctools_export_test', $overridden_export);
193
    ctools_export_load_object_reset('ctools_export_test');
194
    $disabled_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
195

    
196
    $this->assertTrue($disabled_export->disabled, 'The overridden exportable has been disabled.');
197

    
198
    ctools_export_crud_enable('ctools_export_test', $disabled_export);
199
    ctools_export_load_object_reset('ctools_export_test');
200
    $enabled_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
201

    
202
    $this->assertTrue(empty($enabled_export->disabled), 'The overridden exportable has been enabled.');
203

    
204
    // Default object.
205
    $default_export = ctools_export_crud_load('ctools_export_test', 'default_test');
206
    ctools_export_crud_disable('ctools_export_test', $default_export);
207
    ctools_export_load_object_reset('ctools_export_test');
208
    $disabled_export = ctools_export_crud_load('ctools_export_test', 'default_test');
209

    
210
    $this->assertTrue($disabled_export->disabled, 'The default exportable has been disabled.');
211

    
212
    ctools_export_crud_enable('ctools_export_test', $disabled_export);
213
    ctools_export_load_object_reset('ctools_export_test');
214
    $enabled_export = ctools_export_crud_load('ctools_export_test', 'default_test');
215

    
216
    $this->assertTrue(empty($enabled_export->disabled), 'The default exportable has been enabled.');
217
  }
218

    
219
}