1 |
56aebcb7
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Test class for garbage collection of VDE export data.
|
5 |
|
|
*/
|
6 |
|
|
class ViewsDataExportGarbageCollectionTest extends ViewsDataExportBaseTest {
|
7 |
|
|
|
8 |
|
|
protected $profile = 'testing';
|
9 |
|
|
|
10 |
|
|
public static function getInfo() {
|
11 |
|
|
return array(
|
12 |
|
|
'name' => 'Garbage collection',
|
13 |
|
|
'description' => 'Checks garbage collection of batched exports',
|
14 |
|
|
'group' => 'Views Data Export',
|
15 |
|
|
);
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
|
|
* Test that VDE export can only be downloaded by the user that created them.
|
20 |
|
|
*/
|
21 |
|
|
public function testExportedGarbageCollection() {
|
22 |
|
|
// Run a batched export.
|
23 |
|
|
$path = 'vde_test/' . $this->randomName();
|
24 |
|
|
list($view, $expected) = $this->getExportView($path);
|
25 |
|
|
$display = &$view->display['vde_test']->handler;
|
26 |
|
|
// Set this view to be batched.
|
27 |
|
|
$display->override_option('use_batch', 'batch');
|
28 |
|
|
// Save this view so we can hit the path.
|
29 |
|
|
$view->save();
|
30 |
|
|
// Ensure that the menu router system is rebuilt on the next page load.
|
31 |
|
|
variable_set('menu_rebuild_needed', TRUE);
|
32 |
|
|
$exports = $this->getNumberOfStoredExports();
|
33 |
|
|
$files = $this->getNumberOfFiles();
|
34 |
|
|
$this->assertBatchedExportEqual($path, $expected, 'Batched access export matched expected output.');
|
35 |
|
|
// We should have created a new export and file.
|
36 |
|
|
$this->assertEqual($this->getNumberOfStoredExports(), $exports + 1, 'A single new batched export was created');
|
37 |
|
|
$this->assertEqual($this->getNumberOfFiles(), $files + 1, 'A single new temporary file was created');
|
38 |
|
|
|
39 |
|
|
$middle_timestamp = time();
|
40 |
|
|
sleep(1);
|
41 |
|
|
$this->assertBatchedExportEqual($path, $expected, 'Batched access export matched expected output.');
|
42 |
|
|
// We should have created a new export and file.
|
43 |
|
|
$this->assertEqual($this->getNumberOfStoredExports(), $exports + 2, 'A single new batched export was created');
|
44 |
|
|
$this->assertEqual($this->getNumberOfFiles(), $files + 2, 'A single new temporary file was created');
|
45 |
|
|
|
46 |
|
|
// Garbage collect the first export only.
|
47 |
|
|
views_data_export_garbage_collect(REQUEST_TIME - $middle_timestamp);
|
48 |
|
|
$this->assertEqual($this->getNumberOfStoredExports(), $exports + 1, 'Garbage collection removed 1 old export');
|
49 |
|
|
$this->assertEqual($this->getNumberOfFiles(), $files + 1, 'Garbage collection removed 1 old temporary file');
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
protected function getNumberOfStoredExports() {
|
53 |
|
|
return (int) db_select('views_data_export')->countQuery()->execute()->fetchField();
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
protected function getNumberOfFiles() {
|
57 |
|
|
return (int) db_select('file_managed')->countQuery()->execute()->fetchField();
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Build and return a basic view of the views_test table.
|
63 |
|
|
*
|
64 |
|
|
* @return view
|
65 |
|
|
*/
|
66 |
|
|
protected function getBasicExportView() {
|
67 |
|
|
views_include('view');
|
68 |
|
|
|
69 |
|
|
// Create the basic view.
|
70 |
|
|
$view = new view();
|
71 |
|
|
$view->vid = 'new';
|
72 |
|
|
$view->base_table = 'views_test';
|
73 |
|
|
|
74 |
|
|
// Set up the fields we need.
|
75 |
|
|
$display = $view->new_display('default', 'Master', 'default');
|
76 |
|
|
|
77 |
|
|
$display->override_option('fields', array(
|
78 |
|
|
'id' => array(
|
79 |
|
|
'id' => 'id',
|
80 |
|
|
'table' => 'views_test',
|
81 |
|
|
'field' => 'id',
|
82 |
|
|
'relationship' => 'none',
|
83 |
|
|
),
|
84 |
|
|
'name' => array(
|
85 |
|
|
'id' => 'name',
|
86 |
|
|
'table' => 'views_test',
|
87 |
|
|
'field' => 'name',
|
88 |
|
|
'relationship' => 'none',
|
89 |
|
|
),
|
90 |
|
|
'age' => array(
|
91 |
|
|
'id' => 'age',
|
92 |
|
|
'table' => 'views_test',
|
93 |
|
|
'field' => 'age',
|
94 |
|
|
'relationship' => 'none',
|
95 |
|
|
),
|
96 |
|
|
));
|
97 |
|
|
|
98 |
|
|
// Set up the sort order.
|
99 |
|
|
$display->override_option('sorts', array(
|
100 |
|
|
'id' => array(
|
101 |
|
|
'order' => 'ASC',
|
102 |
|
|
'id' => 'id',
|
103 |
|
|
'table' => 'views_test',
|
104 |
|
|
'field' => 'id',
|
105 |
|
|
'relationship' => 'none',
|
106 |
|
|
),
|
107 |
|
|
));
|
108 |
|
|
|
109 |
|
|
// Set up the pager.
|
110 |
|
|
$display->override_option('pager', array(
|
111 |
|
|
'type' => 'none',
|
112 |
|
|
'options' => array('offset' => 0),
|
113 |
|
|
));
|
114 |
|
|
|
115 |
|
|
return $view;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
protected function getStylePluginName() {
|
119 |
|
|
return 'views_data_export_txt';
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
protected function getExportView($path = 'vde_test') {
|
123 |
|
|
// Create the basic view.
|
124 |
|
|
$view = $this->getBasicExportView();
|
125 |
|
|
|
126 |
|
|
$display = $view->new_display('views_data_export', 'Data export', 'vde_test');
|
127 |
|
|
$display->override_option('style_plugin', $this->getStylePluginName());
|
128 |
|
|
$display->override_option('path', $path);
|
129 |
|
|
|
130 |
|
|
$expected = '[ID]
|
131 |
|
|
|
132 |
|
|
1
|
133 |
|
|
[Name]
|
134 |
|
|
|
135 |
|
|
John
|
136 |
|
|
[Age]
|
137 |
|
|
|
138 |
|
|
25
|
139 |
|
|
----------------------------------------
|
140 |
|
|
|
141 |
|
|
[ID]
|
142 |
|
|
|
143 |
|
|
2
|
144 |
|
|
[Name]
|
145 |
|
|
|
146 |
|
|
George
|
147 |
|
|
[Age]
|
148 |
|
|
|
149 |
|
|
27
|
150 |
|
|
----------------------------------------
|
151 |
|
|
|
152 |
|
|
[ID]
|
153 |
|
|
|
154 |
|
|
3
|
155 |
|
|
[Name]
|
156 |
|
|
|
157 |
|
|
Ringo
|
158 |
|
|
[Age]
|
159 |
|
|
|
160 |
|
|
28
|
161 |
|
|
----------------------------------------
|
162 |
|
|
|
163 |
|
|
[ID]
|
164 |
|
|
|
165 |
|
|
4
|
166 |
|
|
[Name]
|
167 |
|
|
|
168 |
|
|
Paul
|
169 |
|
|
[Age]
|
170 |
|
|
|
171 |
|
|
26
|
172 |
|
|
----------------------------------------
|
173 |
|
|
|
174 |
|
|
[ID]
|
175 |
|
|
|
176 |
|
|
5
|
177 |
|
|
[Name]
|
178 |
|
|
|
179 |
|
|
Meredith
|
180 |
|
|
[Age]
|
181 |
|
|
|
182 |
|
|
30
|
183 |
|
|
----------------------------------------';
|
184 |
|
|
|
185 |
|
|
return array(&$view, $expected);
|
186 |
|
|
}
|
187 |
|
|
} |