class BlogAPIModuleTestCase in SimpleTest 6
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \BlogAPIModuleTestCase
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlogAPIModuleTestCase:: |
function | Add a taxonomy term to vocabulary. | ||
BlogAPIModuleTestCase:: |
function | Add taxonomy vocabulary. | ||
BlogAPIModuleTestCase:: |
function | |||
BlogAPIModuleTestCase:: |
function | |||
BlogAPIModuleTestCase:: |
function | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
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:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Retrieves and saves current modules list into $_originalModules and $_modules. | ||
DrupalTestCase:: |
function | Follows a link by name. | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Creates a custom content type based on default settings. | ||
DrupalTestCase:: |
function | Creates a node based on default settings. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Broker for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
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:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a drupal variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
DrupalTestCase:: |
function | tearDown implementation, setting back switched modules etc | 8 |