1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* File fetcher tests.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* File fetcher test class.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsFileFetcherTestCase extends FeedsWebTestCase {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'File fetcher',
|
15 |
|
|
'description' => 'Tests for file fetcher plugin.',
|
16 |
|
|
'group' => 'Feeds',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Test scheduling on cron.
|
22 |
|
|
*/
|
23 |
|
|
public function testPublicFiles() {
|
24 |
|
|
// Set up an importer.
|
25 |
|
|
$this->createImporterConfiguration('Node import', 'node');
|
26 |
|
|
// Set and configure plugins and mappings.
|
27 |
|
|
$this->setSettings('node', NULL, array('content_type' => ''));
|
28 |
|
|
$this->setPlugin('node', 'FeedsFileFetcher');
|
29 |
|
|
$this->setPlugin('node', 'FeedsCSVParser');
|
30 |
|
|
$mappings = array(
|
31 |
|
|
'0' => array(
|
32 |
|
|
'source' => 'title',
|
33 |
|
|
'target' => 'title',
|
34 |
|
|
),
|
35 |
|
|
);
|
36 |
|
|
$this->addMappings('node', $mappings);
|
37 |
|
|
// Straight up upload is covered in other tests, focus on direct mode
|
38 |
|
|
// and file batching here.
|
39 |
|
|
$settings = array(
|
40 |
|
|
'direct' => TRUE,
|
41 |
|
|
'directory' => 'public://feeds',
|
42 |
|
|
);
|
43 |
|
|
$this->setSettings('node', 'FeedsFileFetcher', $settings);
|
44 |
|
|
|
45 |
|
|
// Verify that invalid paths are not accepted.
|
46 |
|
|
foreach (array('/tmp/') as $path) {
|
47 |
|
|
$edit = array(
|
48 |
|
|
'feeds[FeedsFileFetcher][source]' => $path,
|
49 |
|
|
);
|
50 |
|
|
$this->drupalPost('import/node', $edit, t('Import'));
|
51 |
|
|
$this->assertText("The file needs to reside within the site's files directory, its path needs to start with scheme://. Available schemes:");
|
52 |
|
|
$count = db_query("SELECT COUNT(*) FROM {feeds_source} WHERE feed_nid = 0")->fetchField();
|
53 |
|
|
$this->assertEqual($count, 0);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
// Verify batching through directories.
|
57 |
|
|
// Copy directory of files.
|
58 |
|
|
$dir = 'public://batchtest';
|
59 |
|
|
$this->copyDir($this->absolutePath() . '/tests/feeds/batch', $dir);
|
60 |
|
|
|
61 |
|
|
// Ingest directory of files. Set limit to 5 to force processor to batch,
|
62 |
|
|
// too.
|
63 |
|
|
variable_set('feeds_process_limit', 5);
|
64 |
|
|
$edit = array(
|
65 |
|
|
'feeds[FeedsFileFetcher][source]' => $dir,
|
66 |
|
|
);
|
67 |
|
|
$this->drupalPost('import/node', $edit, t('Import'));
|
68 |
|
|
$this->assertText('Created 18 nodes');
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Test uploading private files.
|
73 |
|
|
*/
|
74 |
|
|
public function testPrivateFiles() {
|
75 |
|
|
// Set up an importer.
|
76 |
|
|
$this->createImporterConfiguration('Node import', 'node');
|
77 |
|
|
// Set and configure plugins and mappings.
|
78 |
|
|
$edit = array(
|
79 |
|
|
'content_type' => '',
|
80 |
|
|
);
|
81 |
|
|
$this->drupalPost('admin/structure/feeds/node/settings', $edit, 'Save');
|
82 |
|
|
$this->setPlugin('node', 'FeedsFileFetcher');
|
83 |
|
|
$this->setPlugin('node', 'FeedsCSVParser');
|
84 |
|
|
$mappings = array(
|
85 |
|
|
'0' => array(
|
86 |
|
|
'source' => 'title',
|
87 |
|
|
'target' => 'title',
|
88 |
|
|
),
|
89 |
|
|
);
|
90 |
|
|
$this->addMappings('node', $mappings);
|
91 |
|
|
// Straight up upload is covered in other tests, focus on direct mode
|
92 |
|
|
// and file batching here.
|
93 |
|
|
$settings = array(
|
94 |
|
|
'direct' => TRUE,
|
95 |
|
|
'directory' => 'private://feeds',
|
96 |
|
|
);
|
97 |
|
|
$this->setSettings('node', 'FeedsFileFetcher', $settings);
|
98 |
|
|
|
99 |
|
|
// Verify batching through directories.
|
100 |
|
|
// Copy directory of files.
|
101 |
|
|
$dir = 'private://batchtest';
|
102 |
|
|
$this->copyDir($this->absolutePath() . '/tests/feeds/batch', $dir);
|
103 |
|
|
|
104 |
|
|
// Ingest directory of files. Set limit to 5 to force processor to batch,
|
105 |
|
|
// too.
|
106 |
|
|
variable_set('feeds_process_limit', 5);
|
107 |
|
|
$edit = array(
|
108 |
|
|
'feeds[FeedsFileFetcher][source]' => $dir,
|
109 |
|
|
);
|
110 |
|
|
$this->drupalPost('import/node', $edit, t('Import'));
|
111 |
|
|
$this->assertText('Created 18 nodes');
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
} |