1 |
7295e063
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains FeedsContentTypeTest.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests for when an importer is attached to a content type.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsContentTypeTest extends FeedsWebTestCase {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'Feed content type',
|
15 |
|
|
'description' => 'Tests behavior for when an importer is attached to a content type.',
|
16 |
|
|
'group' => 'Feeds',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
public function setUp() {
|
21 |
|
|
parent::setUp();
|
22 |
|
|
|
23 |
|
|
// Create an importer configuration.
|
24 |
|
|
$this->createImporterConfiguration('Syndication', 'syndication');
|
25 |
|
|
$this->addMappings('syndication',
|
26 |
|
|
array(
|
27 |
|
|
0 => array(
|
28 |
|
|
'source' => 'title',
|
29 |
|
|
'target' => 'title',
|
30 |
|
|
'unique' => FALSE,
|
31 |
|
|
),
|
32 |
|
|
1 => array(
|
33 |
|
|
'source' => 'description',
|
34 |
|
|
'target' => 'body',
|
35 |
|
|
),
|
36 |
|
|
2 => array(
|
37 |
|
|
'source' => 'timestamp',
|
38 |
|
|
'target' => 'created',
|
39 |
|
|
),
|
40 |
|
|
3 => array(
|
41 |
|
|
'source' => 'url',
|
42 |
|
|
'target' => 'url',
|
43 |
|
|
'unique' => TRUE,
|
44 |
|
|
),
|
45 |
|
|
4 => array(
|
46 |
|
|
'source' => 'guid',
|
47 |
|
|
'target' => 'guid',
|
48 |
|
|
'unique' => TRUE,
|
49 |
|
|
),
|
50 |
|
|
)
|
51 |
|
|
);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* Tests if titles can be retrieved from a feed.
|
56 |
|
|
*/
|
57 |
|
|
public function testRetrieveTitleFromFeed() {
|
58 |
|
|
// The Common syndication parser supports retrieving title from feed.
|
59 |
|
|
$edit = array(
|
60 |
|
|
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
|
61 |
|
|
);
|
62 |
|
|
$this->drupalPost('node/add/page', $edit, 'Save');
|
63 |
|
|
|
64 |
|
|
$node = node_load(1);
|
65 |
|
|
$this->assertEqual('Development Seed - Technological Solutions for Progressive Organizations', $node->title, 'The title was retrieved from the feed.');
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Tests if the node title is required when the CSV parser is used.
|
70 |
|
|
*/
|
71 |
|
|
public function testRequiredNodeTitleWithCSVParser() {
|
72 |
|
|
// Set parser to CSV.
|
73 |
|
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
74 |
|
|
|
75 |
|
|
$edit = array(
|
76 |
|
|
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv',
|
77 |
|
|
);
|
78 |
|
|
$this->drupalPost('node/add/page', $edit, 'Save');
|
79 |
|
|
|
80 |
|
|
$this->assertText('Title field is required.');
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/**
|
84 |
|
|
* Tests that the feed node gets no title if the content type does not use the
|
85 |
|
|
* node title field.
|
86 |
|
|
*/
|
87 |
|
|
public function testWithContentTypeWithoutTitle() {
|
88 |
|
|
// Set that the content type 'page' has no title.
|
89 |
|
|
db_update('node_type')
|
90 |
|
|
->fields(array(
|
91 |
|
|
'has_title' => 0,
|
92 |
|
|
))
|
93 |
|
|
->condition('type', 'page')
|
94 |
|
|
->execute();
|
95 |
|
|
|
96 |
|
|
// Flush caches so this change is picked up.
|
97 |
|
|
drupal_flush_all_caches();
|
98 |
|
|
|
99 |
|
|
// And import a RSS feed with a title.
|
100 |
|
|
$edit = array(
|
101 |
|
|
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
|
102 |
|
|
);
|
103 |
|
|
$this->drupalPost('node/add/page', $edit, 'Save');
|
104 |
|
|
|
105 |
|
|
// Assert that the feed node didn't got a title from the source.
|
106 |
|
|
$node = node_load(1);
|
107 |
|
|
$this->assertEqual('', $node->title, 'The feed node has no title.');
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
} |