1 |
ec2b0e7b
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Test cases for entity API integration.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests for Entity API integration.
|
10 |
|
|
*/
|
11 |
|
|
class FeedsEntityCase extends FeedsWebTestCase {
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* {@inheritdoc}
|
15 |
|
|
*/
|
16 |
|
|
public static function getInfo() {
|
17 |
|
|
return array(
|
18 |
|
|
'name' => 'Feeds entity tests',
|
19 |
|
|
'description' => 'Test integration with the entity property API.',
|
20 |
|
|
'group' => 'Feeds',
|
21 |
|
|
'dependencies' => array('entity'),
|
22 |
|
|
);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* {@inheritdoc}
|
27 |
|
|
*/
|
28 |
|
|
public function setUp() {
|
29 |
|
|
parent::setUp(array('entity'));
|
30 |
|
|
|
31 |
|
|
// Create an importer configuration.
|
32 |
|
|
$this->createImporterConfiguration('Syndication', 'syndication');
|
33 |
|
|
$this->addMappings('syndication',
|
34 |
|
|
array(
|
35 |
|
|
0 => array(
|
36 |
|
|
'source' => 'title',
|
37 |
|
|
'target' => 'title',
|
38 |
|
|
'unique' => FALSE,
|
39 |
|
|
),
|
40 |
|
|
1 => array(
|
41 |
|
|
'source' => 'description',
|
42 |
|
|
'target' => 'body',
|
43 |
|
|
),
|
44 |
|
|
2 => array(
|
45 |
|
|
'source' => 'timestamp',
|
46 |
|
|
'target' => 'created',
|
47 |
|
|
),
|
48 |
|
|
3 => array(
|
49 |
|
|
'source' => 'url',
|
50 |
|
|
'target' => 'url',
|
51 |
|
|
'unique' => TRUE,
|
52 |
|
|
),
|
53 |
|
|
4 => array(
|
54 |
|
|
'source' => 'guid',
|
55 |
|
|
'target' => 'guid',
|
56 |
|
|
'unique' => TRUE,
|
57 |
|
|
),
|
58 |
|
|
)
|
59 |
|
|
);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/**
|
63 |
|
|
* Tests getting feeds item properties on an entity.
|
64 |
|
|
*
|
65 |
|
|
* @covers feeds_get_feeds_item_property()
|
66 |
|
|
*/
|
67 |
|
|
public function testGetFeedsItemProperty() {
|
68 |
|
|
// Create a feed node and import 10 items.
|
69 |
|
|
$feed_nid = $this->createFeedNode();
|
70 |
|
|
$this->assertText('Created 10 nodes');
|
71 |
|
|
|
72 |
|
|
// Create entity metadata wrapper for node.
|
73 |
|
|
$node_wrapper = entity_metadata_wrapper('node', 2);
|
74 |
|
|
|
75 |
|
|
// Property 'feed_nid'.
|
76 |
|
|
$this->assertEqual($feed_nid, $node_wrapper->feed_nid->value());
|
77 |
|
|
|
78 |
|
|
// Property 'feed_node'.
|
79 |
|
|
$feed_node = $node_wrapper->feed_node->value();
|
80 |
|
|
$this->assertEqual($feed_nid, $feed_node->nid);
|
81 |
|
|
|
82 |
|
|
// Property 'feeds_item_guid'.
|
83 |
|
|
$this->assertEqual('974 at http://developmentseed.org', $node_wrapper->feeds_item_guid->value());
|
84 |
|
|
|
85 |
|
|
// Property 'feeds_item_url'.
|
86 |
|
|
$this->assertEqual('http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating', $node_wrapper->feeds_item_url->value());
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Tests getting feeds item properties on an existing entity without a
|
91 |
|
|
* feeds_item.
|
92 |
|
|
*
|
93 |
|
|
* @covers feeds_get_feeds_item_property()
|
94 |
|
|
*/
|
95 |
|
|
public function testGetFeedsItemPropertyNoFeedsItem() {
|
96 |
|
|
// Create a new node.
|
97 |
|
|
$node = $this->drupalCreateNode();
|
98 |
|
|
|
99 |
|
|
// Create entity metadata wrapper for node.
|
100 |
|
|
$node_wrapper = entity_metadata_wrapper('node', $node);
|
101 |
|
|
|
102 |
|
|
// Assert NULL for each property.
|
103 |
|
|
$this->assertNull($node_wrapper->feed_nid->value());
|
104 |
|
|
$this->assertNull($node_wrapper->feed_node->value());
|
105 |
|
|
$this->assertNull($node_wrapper->feeds_item_guid->value());
|
106 |
|
|
$this->assertNull($node_wrapper->feeds_item_url->value());
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* Tests getting feeds item properties on a new entity.
|
111 |
|
|
*
|
112 |
|
|
* @covers feeds_get_feeds_item_property()
|
113 |
|
|
*/
|
114 |
|
|
public function testGetFeedsItemPropertyNewEntity() {
|
115 |
|
|
// Create a feed node and import 10 items.
|
116 |
|
|
$feed_nid = $this->createFeedNode();
|
117 |
|
|
$this->assertText('Created 10 nodes');
|
118 |
|
|
|
119 |
|
|
// Create a new node.
|
120 |
|
|
$node = new stdClass();
|
121 |
|
|
$node->type = 'page';
|
122 |
|
|
$node->title = $this->randomName(8);
|
123 |
|
|
$node->changed = REQUEST_TIME;
|
124 |
|
|
$node->created = REQUEST_TIME;
|
125 |
|
|
$node->is_new = TRUE;
|
126 |
|
|
node_object_prepare($node);
|
127 |
|
|
// Populate properties that are set by node_object_prepare().
|
128 |
|
|
$node->log = 'Created by FeedsNodeProcessor';
|
129 |
|
|
$node->uid = 0;
|
130 |
|
|
|
131 |
|
|
// Add a feeds_item property on the node.
|
132 |
|
|
$node->feeds_item = new stdClass();
|
133 |
|
|
$node->feeds_item->is_new = TRUE;
|
134 |
|
|
$node->feeds_item->entity_id = 0;
|
135 |
|
|
$node->feeds_item->entity_type = 'node';
|
136 |
|
|
$node->feeds_item->id = 'syndication';
|
137 |
|
|
$node->feeds_item->feed_nid = $feed_nid;
|
138 |
|
|
$node->feeds_item->imported = REQUEST_TIME;
|
139 |
|
|
$node->feeds_item->hash = '';
|
140 |
|
|
$node->feeds_item->url = 'http://www.example.com';
|
141 |
|
|
$node->feeds_item->guid = '1234';
|
142 |
|
|
|
143 |
|
|
// Create entity metadata wrapper for node.
|
144 |
|
|
$node_wrapper = entity_metadata_wrapper('node', $node);
|
145 |
|
|
|
146 |
|
|
// Property 'feed_nid'.
|
147 |
|
|
$this->assertEqual($feed_nid, $node_wrapper->feed_nid->value());
|
148 |
|
|
|
149 |
|
|
// Property 'feed_node'.
|
150 |
|
|
$feed_node = $node_wrapper->feed_node->value();
|
151 |
|
|
$this->assertEqual($feed_nid, $feed_node->nid);
|
152 |
|
|
|
153 |
|
|
// Property 'feeds_item_guid'.
|
154 |
|
|
$this->assertEqual('1234', $node_wrapper->feeds_item_guid->value());
|
155 |
|
|
|
156 |
|
|
// Property 'feeds_item_url'.
|
157 |
|
|
$this->assertEqual('http://www.example.com', $node_wrapper->feeds_item_url->value());
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
/**
|
161 |
|
|
* Tests getting feeds item properties on a new entity without a feeds_item.
|
162 |
|
|
*
|
163 |
|
|
* @covers feeds_get_feeds_item_property()
|
164 |
|
|
*/
|
165 |
|
|
public function testGetFeedsItemPropertyNewEntityNoFeedsItem() {
|
166 |
|
|
// Create a new node.
|
167 |
|
|
$node = new stdClass();
|
168 |
|
|
$node->type = 'page';
|
169 |
|
|
$node->title = $this->randomName(8);
|
170 |
|
|
$node->changed = REQUEST_TIME;
|
171 |
|
|
$node->created = REQUEST_TIME;
|
172 |
|
|
$node->is_new = TRUE;
|
173 |
|
|
node_object_prepare($node);
|
174 |
|
|
// Populate properties that are set by node_object_prepare().
|
175 |
|
|
$node->log = 'Created by FeedsNodeProcessor';
|
176 |
|
|
$node->uid = 0;
|
177 |
|
|
|
178 |
|
|
// Create entity metadata wrapper for node.
|
179 |
|
|
$node_wrapper = entity_metadata_wrapper('node', $node);
|
180 |
|
|
|
181 |
|
|
// Assert NULL for each property.
|
182 |
|
|
$this->assertNull($node_wrapper->feed_nid->value());
|
183 |
|
|
$this->assertNull($node_wrapper->feed_node->value());
|
184 |
|
|
$this->assertNull($node_wrapper->feeds_item_guid->value());
|
185 |
|
|
$this->assertNull($node_wrapper->feeds_item_url->value());
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
} |