You are here

public function BlogapiBloggerEndpointTestCase::testEditPost in Blog API 7.2

Test blogger.editPost().

File

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

Class

BlogapiBloggerEndpointTestCase
@file Endpoint tests for BlogAPI Blogger

Code

public function testEditPost() {

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

  // Allow to user our content type with BlogAPI
  variable_set('blogapi_node_types', array(
    $allowed_type->type,
  ));
  $wrong_node = $this
    ->drupalCreateNode(array(
    'type' => $disallowed_type->type,
  ));
  $correct_node = $this
    ->drupalCreateNode(array(
    'type' => $allowed_type->type,
    'title' => $node_title,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $node_body,
        ),
      ),
    ),
  ));

  // Test edit unexisting node
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.editPost' => array(
      '1234567890',
      0,
      $this->privilegedUser->name,
      $this->privilegedUser->pass_raw,
      $content,
      TRUE,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_error_msg(), format_string('Node @nid not found', array(
    '@nid' => 0,
  )), 'Not found error returned');

  // Try to update node with unprevileged user
  $nid = xmlrpc($this->xmlrpcUrl, array(
    'blogger.editPost' => array(
      '1234567890',
      $correct_node->nid,
      $this->privilegedUser->name,
      $this->privilegedUser->pass_raw,
      $content,
      TRUE,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_error_msg(), 'You do not have permission to update this post.', 'User must have node edit permissions');
  $node_title .= ' modified title';
  $node_body .= ' modified body';
  $result = xmlrpc($this->xmlrpcUrl, array(
    'blogger.editPost' => array(
      '1234567890',
      $correct_node->nid,
      $this->privilegedUser2->name,
      $this->privilegedUser2->pass_raw,
      '<title>' . $node_title . '</title>' . $node_body,
      TRUE,
    ),
  ));
  $new_node = node_load($correct_node->nid, NULL, TRUE);
  $this
    ->assertTrue($result && $new_node->title != $correct_node->title, 'Node was updated');
  $this
    ->assertTrue($new_node->title == $node_title, 'Title was updated');
  $this
    ->assertTrue(!empty($new_node->body[LANGUAGE_NONE][0]['value']) && $new_node->body[LANGUAGE_NONE][0]['value'] == $node_body, 'Body was updated');
}