'XML Export',
'description' => 'Various tests for exporting to XML.',
'group' => 'Views Data Export',
);
}
protected $vde_export_type = 'XML';
protected function getStylePluginName() {
return 'views_data_export_xml';
}
protected function getExportView($path = 'vde_test') {
// Create the basic view.
$view = $this->getBasicExportView();
$display = $view->new_display('views_data_export', 'Data export', 'vde_test');
$display->override_option('style_plugin', 'views_data_export_xml');
$display->override_option('path', $path);
$expected = '
1
John
25
2
George
27
3
Ringo
28
4
Paul
26
5
Meredith
30
';
return array(&$view, $expected);
}
/**
* Test to check if empty fields are correctly hidden.
*/
protected function testHideEmptySupport() {
$view = $this->getHideIfEmptyExportView();
// We need to ensure that the test fields are actually empty/0.
db_update('views_test')
->fields(array('age' => 0,))
->condition('name', 'Paul')
->execute();
db_update('views_test')
->fields(array('name' => '',))
->condition('name', 'George')
->execute();
db_update('views_test')
->fields(array('name' => 0,))
->condition('name', 'John')
->execute();
$expected = '
1
0
25
2
27
3
Ringo
28
4
Paul
5
Meredith
30
';
$message = 'Hide if empty support for ' . $this->vde_export_type . ' export matched expected output.';
$this->executeAndCompareGivenView($view, $expected, $message);
}
/**
* Test to ensure that valid XML is produced when someone doesn't specify a label.
*/
protected function testEmptyLabels() {
$view = $this->getBasicExportView();
$display = $view->display['default']->handler;
$display->override_option('fields', array(
'id' => array(
'id' => 'id',
'table' => 'views_test',
'field' => 'id',
'relationship' => 'none',
),
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
// Remove the label from the name field.
'label' => '',
),
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
// Make this label intentially invalid XML.
'label' => '.',
),
));
$expected = '
1
John
25
2
George
27
3
Ringo
28
4
Paul
26
5
Meredith
30
';
$message = 'Empty label test in ' . $this->vde_export_type . ' export matched expected output.';
$this->executeAndCompareGivenView($view, $expected, $message);
}
/**
* Test to ensure that XML nodes names can be manually specified.
*/
protected function testCustomiseXMLNodes() {
$view = $this->getBasicExportView();
// Load the include that contains the _views_data_export_xml_tag_clean function.
module_load_include('inc', 'views_data_export', 'theme/views_data_export.theme');
$root_node = _views_data_export_xml_tag_clean($this->randomName());
$item_node = _views_data_export_xml_tag_clean($this->randomName());
$style_options = array(
'root_node' => $root_node,
'item_node' => $item_node,
);
$expected = '
<' . $root_node . '>
<' . $item_node . '>
1
John
25
' . $item_node . '>
<' . $item_node . '>
2
George
27
' . $item_node . '>
<' . $item_node . '>
3
Ringo
28
' . $item_node . '>
<' . $item_node . '>
4
Paul
26
' . $item_node . '>
<' . $item_node . '>
5
Meredith
30
' . $item_node . '>
' . $root_node . '>';
$message = 'Custom XML nodes test in ' . $this->vde_export_type . ' export matched expected output.';
$this->executeAndCompareGivenView($view, $expected, $message, $style_options);
}
/**
* Test to ensure certain fields can be optionally non-escaped.
*/
protected function testXMLNoEntityEncode() {
$view = $this->getBasicExportView();
$display = $view->display['default']->handler;
$style_options = array(
'no_entity_encode' => array(
'id' => 'id',
),
);
$display->override_option('fields', array(
'id' => array(
'id' => 'id',
'table' => 'views_test',
'field' => 'id',
'relationship' => 'none',
'alter' => array(
'alter_text' => TRUE,
'text' => '[id]',
),
),
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
'alter' => array(
'alter_text' => TRUE,
'text' => '[name]',
),
),
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
),
));
$expected = '
1
<em>John</em>
25
2
<em>George</em>
27
3
<em>Ringo</em>
28
4
<em>Paul</em>
26
5
<em>Meredith</em>
30
';
$message = 'XML in values test in ' . $this->vde_export_type . ' export matched expected output.';
$this->executeAndCompareGivenView($view, $expected, $message, $style_options);
}
/**
* Test to ensure certain fields can be optionally non-escaped.
*/
protected function testXMLCDATAWrapper() {
$view = $this->getBasicExportView();
$style_options = array(
'cdata_wrapper' => array(
'id' => 'id',
'name' => 'name',
),
);
$display = $view->display['default']->handler;
$display->override_option('fields', array(
'id' => array(
'id' => 'id',
'table' => 'views_test',
'field' => 'id',
'relationship' => 'none',
),
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
'alter' => array(
'alter_text' => TRUE,
'text' => '[name]',
),
),
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
),
));
$expected = '
John]]>
25
George]]>
27
Ringo]]>
28
Paul]]>
26
Meredith]]>
30
';
$message = 'XML in values test in ' . $this->vde_export_type . ' export matched expected output.';
$this->executeAndCompareGivenView($view, $expected, $message, $style_options);
}
}