-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.test
112 lines (87 loc) · 3.23 KB
/
storage.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
class StorageAPITestCase extends DrupalWebTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'Storage',
'description' => 'Test Storage.',
'group' => 'Storage',
);
}
function setUp() {
parent::setUp('storage');
$web_user = $this->drupalCreateUser(array('administer storage'));
$this->drupalLogin($web_user);
}
function testStorage() {
$class = storage_class_load(1);
$this->assertNotNull($class, t('Everything class created.'));
$this->assertEqual($class->options['initial_container_id'], 1, t('Initial container set.'));
$path = storage_new_local_storage_path();
$container = array(
'name' => t('Local2'),
'service_id' => 'storage:fs',
'settings' => array(
'path' => $path,
'base_url' => $path,
),
);
$container = storage_container_new($container, FALSE);
$container->create();
$class->options['initial_container_id'] = $container->container_id;
drupal_write_record('storage_class', $class, 'class_id');
$class = storage_class_load(1);
$this->assertEqual($class->options['initial_container_id'], $container->container_id, t('Initial container changed.'));
$selector = storage_selector('storage', 'test');
$selector->create();
$options = array(
'source_uri' => 'modules/simpletest/files/html-1.txt',
'get_filename' => TRUE,
);
$storage = $selector->storageAdd($options);
$this->assertNotNull($storage, t('Store file.'));
$exists = db_select('storage_instance')
->condition('file_id', $storage->file_id)
->condition('container_id', $container->container_id)
->countQuery()
->execute()
->fetchField();
$this->assertTrue($exists, t('Intial instance exists.'));
$this->cronRun();
$exists = db_select('storage_instance')
->condition('file_id', $storage->file_id)
->condition('container_id', 1)
->countQuery()
->execute()
->fetchField();
$this->assertTrue($exists, t('Final instance exists.'));
$exists = db_select('storage_instance')
->condition('file_id', $storage->file_id)
->condition('container_id', $container->container_id)
->countQuery()
->execute()
->fetchField();
$this->assertFalse($exists, t('Intial instance removed.'));
// Create another class.
$class2 = new StorageClass(array(
'name' => t('AAA'),
'options' => array(
'redirect' => FALSE,
'serve_source_uri' => FALSE,
)
));
$class2->create();
$selector = storage_selector('storage', 'test2');
$selector->create($class->class_id);
$this->assertEqual($selector->storageClass()->class_id, $class->class_id, t('Class set when creating selector.'));
// Only test data URIs if core supports them.
if (storage_test_theme_image_data_uri()) {
$class->options['data_uri'] = TRUE;
$class->update();
$storage = storage_load($storage->storage_id);
$output = $storage->serveURL();
$expected = 'data:text/plain;charset=us-ascii;base64,PGgxPlNpbXBsZVRlc3QgSFRNTDwvaDE+';
$this->assertEqual($output, $expected, t('Correct data URI created.'));
}
}
}