You are here

public function BlogapiBloggerEndpointTestCase::testNewPost in Blog API 7.2

Test blogger.newPost()

File

modules/blogapi_blogger/blogapi_blogger.test, line 103
Endpoint tests for BlogAPI Blogger

Class

BlogapiBloggerEndpointTestCase
@file Endpoint tests for BlogAPI Blogger

Code

public function testNewPost() {

  // Prepare data for nodes
  $node_title = $this
    ->randomString();
  $node_body = $this
    ->randomString();
  $content = '<title>' . $node_title . '</title>' . $node_body;
  $missed_type = '_arcticle';

  // Try to create the node. This should fail because the user does not have
  // permission to create this content type.
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.newPost' => array(
      '1234567890',
      $missed_type,
      $this->privilegedUser->name,
      $this->privilegedUser->pass_raw,
      $content,
      TRUE,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_error_msg(), 'You do not have permission to create this type of post.', 'Node access is being respected.');

  // Try to create the node. This should fail because the user does not have
  // permission to create this content type.
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.newPost' => array(
      '1234567890',
      $missed_type,
      $this->privilegedUser2->name,
      $this->privilegedUser2->pass_raw,
      $content,
      TRUE,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_error_msg(), format_string('BlogAPI is not configured to support the @type content type.', array(
    '@type' => $missed_type,
  )), $missed_type . ' type is missed.');

  // Create a content type.
  $type = $this
    ->drupalCreateContentType();

  // Test with existing content type but not allowed for BlogAPI
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.newPost' => array(
      '1234567890',
      $type->type,
      $this->privilegedUser2->name,
      $this->privilegedUser2->pass_raw,
      $content,
      TRUE,
    ),
  ));
  $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,
  ));

  // Create the node. This should work because the user has administer nodes.
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.newPost' => array(
      '1234567890',
      $type->type,
      $this->privilegedUser2->name,
      $this->privilegedUser2->pass_raw,
      $content,
      TRUE,
    ),
  ));

  // Load the node and validate the data.
  $node = node_load($nid);
  $this
    ->assertEqual($node->title, $node_title, 'New node title is set correctly.');
  $this
    ->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $node_body, 'New node body is set correctly.');
  $this
    ->assertEqual($node->status, 1, 'New node is published');
}