public function BlogapiBloggerEndpointTestCase::testGetRecentPosts in Blog API 7.2
Test blogger.getRecentPosts().
File
- modules/
blogapi_blogger/ blogapi_blogger.test, line 321 - Endpoint tests for BlogAPI Blogger
Class
- BlogapiBloggerEndpointTestCase
- @file Endpoint tests for BlogAPI Blogger
Code
public function testGetRecentPosts() {
$type = $this
->drupalCreateContentType();
$number_of_posts = 9;
$nodes = array();
for ($i = 0; $i < 11; $i++) {
$nodes[] = $this
->drupalCreateNode(array(
'type' => $type->type,
'uid' => $this->privilegedUser2->uid,
));
}
// Test user without node view permission.
$result = xmlrpc($this->xmlrpcUrl, array(
'blogger.getRecentPosts' => array(
'1234567890',
$type->type,
$this->privilegedUser->name,
$this->privilegedUser->pass_raw,
$number_of_posts,
),
));
$this
->assertEqual(xmlrpc_error_msg(), format_string('BlogAPI is not configured to support the @type content type.', array(
'@type' => $type->type,
)), $type->type . ' is not allowed for BlogAPI yet.');
// Allow to user our content type with BlogAPI
variable_set('blogapi_node_types', array(
$type->type,
));
// Test user without node view permission.
$results = xmlrpc($this->xmlrpcUrl, array(
'blogger.getRecentPosts' => array(
'1234567890',
$type->type,
$this->privilegedUser2->name,
$this->privilegedUser2->pass_raw,
$number_of_posts,
),
));
$this
->assertTrue(is_array($results) && count($results) == $number_of_posts, 'Service returned correct posts number');
$success = TRUE;
foreach ($results as $post) {
$node = node_load($post['postid']);
if (empty($node) || $node->title != $post['title'] || !empty($node->body[LANGUAGE_NONE][0]['value']) && $node->body[LANGUAGE_NONE][0]['value'] != $post['description']) {
$success = FALSE;
}
}
$this
->assertTrue($success, 'All nodes were retrieved properly');
}