You are here

class BlogAPIModuleTestCase in SimpleTest 6

Hierarchy

Expanded class hierarchy of BlogAPIModuleTestCase

File

tests/blogapi_module.test, line 3

View source
class BlogAPIModuleTestCase extends DrupalTestCase {
  function get_info() {
    return array(
      'name' => t('BlogAPI functionality'),
      'desc' => t('Create, edit, and delete post; upload file; and set/get categories.'),
      'group' => t('Blog API Tests'),
    );
  }
  function setUp() {
    parent::setUp();
    $this
      ->drupalModuleEnable('blog');
    $this
      ->drupalModuleEnable('blogapi');
    $this
      ->drupalModuleEnable('taxonomy');
  }
  function test_blog_API() {

    // Create admin user and taxononmy for later use.
    $admin_user = $this
      ->drupalCreateUserRolePerm(array(
      'administer taxonomy',
    ));
    $this
      ->drupalLoginUser($admin_user);
    $vid = $this
      ->add_vocabulary('simpletest_vocab');
    $term = $this
      ->add_term($vid, 'simpletest_term1');
    $this
      ->drupalGet('logout');

    // Create user.
    $web_user = $this
      ->drupalCreateUserRolePerm(array(
      'create blog entries',
      'delete own blog entries',
      'edit own blog entries',
      'administer content with blog api',
    ));
    $this
      ->drupalLoginUser($web_user);

    // Init common variables.
    $local = url('xmlrpc.php', array(
      'absolute' => TRUE,
    ));
    $appid = 'simpletest';

    // Get user's blog.
    $result = xmlrpc($local, 'blogger.getUsersBlogs', $appid, $web_user->name, $web_user->pass_raw);
    $this
      ->assertTrue($result, 'Request for user\'s blogs returned correctly.');
    if ($result !== FALSE) {
      $this
        ->assertTrue(array_key_exists('url', $result[0]), 'Blog found.');
      if (array_key_exists('url', $result[0])) {
        $blog_id = substr($result[0]['url'], strrpos($result[0]['url'], '/') + 1);
      }
    }

    // Create post.
    $content = $this
      ->randomName(10);
    $result = xmlrpc($local, 'blogger.newPost', $appid, $blog_id, $web_user->name, $web_user->pass_raw, $content, TRUE);
    $this
      ->assertTrue($result, 'Post created.');
    $nid = $result;

    // Check recent posts.
    $result = xmlrpc($local, 'blogger.getRecentPosts', $appid, $blog_id, $web_user->name, $web_user->pass_raw, 5);
    $this
      ->assertTrue($result, 'Recent post list retreived.');
    if ($result !== FALSE && array_key_exists('title', $result[0])) {
      $this
        ->assertEqual($content, $result[0]['title'], 'Post found.');
    }
    else {
      $this
        ->assertTrue(false, 'Post found.');
    }

    // Edit post.
    $content_new = $this
      ->randomName(10);
    $result = xmlrpc($local, 'blogger.editPost', $appid, $nid, $web_user->name, $web_user->pass_raw, $content_new, TRUE);
    $this
      ->assertTrue($result, 'Post successfully modified.');

    // Upload file.
    $file_contents = 'This is a test file that will be transfered via BlogAPI!';
    $file = array();
    $file['name'] = $this
      ->randomName() . '.txt';
    $file['type'] = 'text';
    $file['bits'] = xmlrpc_base64($file_contents);
    $result = xmlrpc($local, 'metaWeblog.newMediaObject', $blog_id, $web_user->name, $web_user->pass_raw, $file);
    $this
      ->assertTrue($result, 'File successfully uploaded.');
    $url = array_key_exists('url', $result) ? $result['url'] : '';

    // Check uploaded file.
    $this
      ->drupalGet($url);
    $this
      ->assertEqual($this
      ->drupalGetContent(), $file_contents, 'Uploaded contents verified.');

    // Set post categories.
    $categories = array(
      array(
        'categoryId' => $term,
      ),
    );
    $result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
    $this
      ->assertTrue($result, 'Post categories set.');

    // Get post categories.
    $result = xmlrpc($local, 'mt.getPostCategories', $nid, $web_user->name, $web_user->pass_raw);
    $this
      ->assertTrue($result, 'Category list successfully retreived.');
    if ($result !== FALSE && array_key_exists('categoryId', $result[0])) {
      $this
        ->assertEqual($term, $result[0]['categoryId'], 'Category list verified.');
    }

    // Delete post.
    $result = xmlrpc($local, 'blogger.deletePost', $appid, $nid, $web_user->name, $web_user->pass_raw, TRUE);
    $this
      ->assertTrue($result, 'Post successfully deleted.');
    $this
      ->drupalGet('logout');

    // Remove taxonmy vocab.
    $this
      ->drupalLoginUser($admin_user);
    $this
      ->drupalPost('admin/content/taxonomy/edit/vocabulary/' . $vid, array(), 'Delete');
    $this
      ->drupalPost(NULL, array(), 'Delete');
    $this
      ->assertWantedRaw(t('Deleted vocabulary %vocab.', array(
      '%vocab' => 'simpletest_vocab',
    )), 'Removed vocabulary.');
  }

  /**
   * Add taxonomy vocabulary.
   *
   * @param string $vocab Vocabulary name.
   */
  function add_vocabulary($vocab) {
    $edit = array();
    $edit['name'] = $vocab;
    $edit['nodes[blog]'] = TRUE;
    $this
      ->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, 'Save');
    $this
      ->assertWantedRaw(t('Created new vocabulary %vocab.', array(
      '%vocab' => $edit['name'],
    )), 'Taxonomy vocabulary added.');
    $vocab_arr = taxonomy_get_vocabularies();
    $vid = NULL;
    foreach ($vocab_arr as $vocab_item) {
      if ($vocab_item->name == $vocab) {
        $vid = $vocab_item->vid;
        break;
      }
    }
    $this
      ->assertNotNull($vid, 'Vocabulary found in database.');
    return $vid;
  }

  /**
   * Add a taxonomy term to vocabulary.
   *
   * @param integer $vid Vocabulary id.
   * @param string $term Term name.
   */
  function add_term($vid, $term) {
    $edit = array();
    $edit['name'] = $term;
    $this
      ->drupalPost('admin/content/taxonomy/' . $vid . '/add/term', $edit, 'Save');
    $this
      ->assertWantedRaw(t('Created new term %term.', array(
      '%term' => $edit['name'],
    )), 'Taxonomy term added.');
    $tree = taxonomy_get_tree($vid);
    $tid = NULL;
    foreach ($tree as $tree_term) {
      if ($tree_term->name == $term) {
        $tid = $tree_term->tid;
        break;
      }
    }
    $this
      ->assertNotNull($tid, 'Term found in database.');
    return $tid;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlogAPIModuleTestCase::add_term function Add a taxonomy term to vocabulary.
BlogAPIModuleTestCase::add_vocabulary function Add taxonomy vocabulary.
BlogAPIModuleTestCase::get_info function
BlogAPIModuleTestCase::setUp function
BlogAPIModuleTestCase::test_blog_API function
DrupalTestCase::$_cleanupContentTypes property
DrupalTestCase::$_cleanupNodes property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::$_modules property
DrupalTestCase::$_originalModules property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::checkOriginalModules function Retrieves and saves current modules list into $_originalModules and $_modules.
DrupalTestCase::clickLink function Follows a link by name.
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateContentType function Creates a custom content type based on default settings.
DrupalTestCase::drupalCreateNode function Creates a node based on default settings.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Broker for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPost function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser By $reporting you specify if this request does assertions or not Warning: empty ("") returns will cause fails with $reporting
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a drupal variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 8