protected function FeedsCSVParserTestCase::getTemplateDataProvider in Feeds 7.2
Data provider for ::testGetTemplate().
1 call to FeedsCSVParserTestCase::getTemplateDataProvider()
- FeedsCSVParserTestCase::testGetTemplate in tests/
feeds_parser_csv.test - Tests if a CSV template is generated properly using various settings.
File
- tests/
feeds_parser_csv.test, line 149 - Contains FeedsCSVParserTestCase.
Class
- FeedsCSVParserTestCase
- Tests the CSV parser using the UI.
Code
protected function getTemplateDataProvider() {
return array(
// Delimiter ',' test. Source keys containing a ',' should be wrapped in
// quotes.
array(
'delimiter' => ',',
'mapping' => array(
array(
'source' => 'title+;|',
'target' => 'title',
),
array(
'source' => 'alpha, beta + gamma',
'target' => 'body',
),
array(
'source' => 'guid',
'target' => 'guid',
),
),
'expected' => 'title+;|,"alpha, beta + gamma",guid',
'texts' => array(
'columns' => 'title+;|, "alpha, beta + gamma", guid',
),
),
// Delimiter ';' test. Source keys containing a ';' should be wrapped in
// quotes.
array(
'delimiter' => ';',
'mapping' => array(
array(
'source' => 'title;)',
'target' => 'title',
),
array(
'source' => 'alpha, beta + gamma',
'target' => 'body',
),
array(
'source' => 'guid',
'target' => 'guid',
),
),
'expected' => '"title;)";alpha, beta + gamma;guid',
'texts' => array(
'columns' => 'title;), "alpha, beta + gamma", guid',
),
),
// Delimiter 'TAB' test.
array(
'delimiter' => 'TAB',
'mapping' => array(
array(
'source' => 'title,;|',
'target' => 'title',
),
array(
'source' => 'alpha, beta + gamma',
'target' => 'body',
),
array(
'source' => 'guid',
'target' => 'guid',
),
),
'expected' => 'title,;| alpha, beta + gamma guid',
'texts' => array(
'columns' => '"title,;|", "alpha, beta + gamma", guid',
),
),
// Delimiter '|' test. Source keys containing a '|' should be wrapped in
// quotes.
array(
'delimiter' => '|',
'mapping' => array(
array(
'source' => 'title+;,',
'target' => 'title',
),
array(
'source' => 'alpha|beta|gamma',
'target' => 'body',
),
array(
'source' => 'guid',
'target' => 'guid',
),
),
'expected' => 'title+;,|"alpha|beta|gamma"|guid',
'texts' => array(
'columns' => '"title+;,", alpha|beta|gamma, guid',
),
),
// Delimiter '+' test. Source keys containing a '+' should be wrapped in
// quotes.
array(
'delimiter' => '+',
'mapping' => array(
array(
'source' => 'title,;|',
'target' => 'title',
),
array(
'source' => 'alpha, beta + gamma',
'target' => 'body',
),
array(
'source' => 'guid',
'target' => 'guid',
),
),
'expected' => 'title,;|+"alpha, beta + gamma"+guid',
'texts' => array(
'columns' => '"title,;|", "alpha, beta + gamma", guid',
),
),
// Ensure that when a source key is used multiple times in mapping, the
// key is only printed once in the CSV template.
array(
'delimiter' => ',',
'mapping' => array(
array(
'source' => 'text',
'target' => 'title',
'unique' => TRUE,
),
array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
array(
'source' => 'date',
'target' => 'created',
),
array(
'source' => 'date',
'target' => 'changed',
),
array(
'source' => 'text',
'target' => 'body',
),
),
'expected' => 'text,guid,date',
'texts' => array(
'columns' => 'text, guid, date',
'unique' => 'Columns text, guid are mandatory and values in these columns are considered unique',
),
),
// Special characters. Things like '&' shouldn't be converted to '&'
// for example.
array(
'delimiter' => ',',
'mapping' => array(
array(
'source' => '&',
'target' => 'title',
'unique' => TRUE,
),
array(
'source' => 'alpha&beta',
'target' => 'body',
),
array(
'source' => '<created>',
'target' => 'created',
),
array(
'source' => '\'guid\'',
'target' => 'guid',
),
),
'expected' => '&,alpha&beta,<created>,\'guid\'',
'texts' => array(
'columns' => '&, alpha&beta, <created>, \'guid\'',
'unique' => 'Column & is mandatory and considered unique',
),
),
// Blank sources (source which name only contains spaces) should not end
// up in the template, but a zero should.
array(
'delimiter' => ',',
'mapping' => array(
array(
'source' => '0',
'target' => 'body',
),
array(
'source' => ' ',
'target' => 'guid',
'unique' => TRUE,
),
),
'expected' => '0',
'texts' => array(
'columns' => '0',
),
),
);
}