Commit 75722e4f authored by Dries's avatar Dries
Browse files

- Patch #537434 by chx, bangpound, moshe weitzman, David Strauss: move the...

- Patch #537434 by chx, bangpound, moshe weitzman, David Strauss: move the blog API module to contrib.
parent 59422f6a
......@@ -164,6 +164,8 @@ Drupal 7.0, xxxx-xx-xx (development version)
experience.
- Better module version support.
* Modules now can specify which version of another module they depend on.
- Blog API
* This module has been removed from core.
- Improved node access control system.
* All modules may now influence the access to a node at runtime, not just
the module that defined a node.
......
......@@ -3,9 +3,6 @@
List of maintainers
--------------------------------------------------------------------------------
BLOG API
James Walker 'walkah' <http://drupal.org/user/1531>
DATABASE SYSTEM
Larry Garfield 'Crell' <http://drupal.org/user/26398>
......
; $Id$
name = Blog API
description = Allows users to post content using applications that support XML-RPC blog APIs.
package = Core
version = VERSION
core = 7.x
files[] = blogapi.module
files[] = blogapi.install
files[] = blogapi.test
<?php
// $Id$
/**
* @file
* Install, update and uninstall functions for the blogapi module.
*/
/**
* Implement hook_install().
*/
function blogapi_install() {
// Create tables.
drupal_install_schema('blogapi');
}
/**
* Implement hook_uninstall().
*/
function blogapi_uninstall() {
// Remove tables.
drupal_uninstall_schema('blogapi');
}
/**
* Implement hook_schema().
*/
function blogapi_schema() {
$schema['blogapi_files'] = array(
'description' => 'Stores information for files uploaded via the blogapi.',
'fields' => array(
'fid' => array(
'description' => 'Primary Key: Unique file ID.',
'type' => 'serial',
),
'uid' => array(
'description' => 'The {users}.uid of the user who is associated with the file.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'filepath' => array(
'description' => 'Path of the file relative to Drupal root.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'filesize' => array(
'description' => 'The size of the file in bytes.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('fid'),
'indexes' => array(
'uid' => array('uid'),
),
'foreign keys' => array(
'uid' => array('users' => 'uid'),
),
);
return $schema;
}
This diff is collapsed.
<?php
// $Id$
class BlogAPITestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Blog API functionality',
'description' => 'Create, edit, and delete post; upload file; and set/get categories.',
'group' => 'Blog API',
);
}
function setUp() {
parent::setUp('blog', 'blogapi', 'taxonomy');
}
/**
* Create, edit, and delete post; upload file; set/get categories.
*/
function testBlogAPI() {
global $base_url;
// Create user.
$web_user = $this->drupalCreateUser(array('create blog content', 'delete own blog content', 'edit own blog content', 'administer content with blog api'));
// Create admin user and taxonomy for later use.
$admin_user = $this->drupalCreateUser(array('administer taxonomy'));
$this->drupalLogin($admin_user);
$vid = $this->addVocabulary('simpletest_vocab');
$term_1 = $this->addTerm($vid, 'simpletest_term1');
$term_2 = $this->addTerm($vid, 'simpletest_term2');
// Init common variables.
$local = url($base_url . '/xmlrpc.php', array('external' => TRUE));
$appid = 'simpletest';
// Get user's blog.
$result = xmlrpc($local, 'blogger.getUsersBlogs', $appid, $web_user->name, $web_user->pass_raw);
$this->assertTrue($result, t('Request for user\'s blogs returned correctly.'));
if ($result !== FALSE) {
if ($this->assertTrue(array_key_exists('blogid', $result[0]), t('Blog found.'))) {
$blog_id = $result[0]['blogid'];
}
}
// Create post.
$content = $this->randomName(32);
$result = xmlrpc($local, 'blogger.newPost', $appid, $blog_id, $web_user->name, $web_user->pass_raw, $content, TRUE);
$this->assertTrue($result, t('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, t('Recent post list retrieved.'));
if ($result !== FALSE && array_key_exists('title', $result[0])) {
$this->assertEqual($content, $result[0]['title'], t('Post found.'));
}
else {
$this->fail(t('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, t('Post successfully modified.'));
// Upload file.
$file = current($this->drupalGetTestFiles('text'));
$file_contents = file_get_contents($file->uri);
$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, t('File successfully uploaded.'));
$url = (array_key_exists('url', $result) ? $result['url'] : '');
// Check uploaded file.
$this->drupalGet($url);
$this->assertEqual($this->drupalGetContent(), $file_contents, t('Uploaded contents verified.'));
// Set post categories.
$categories = array(array('categoryId' => $term_1));
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
$this->assertTrue($result, t('Post categories set.'));
// Get post categories.
$result = xmlrpc($local, 'mt.getPostCategories', $nid, $web_user->name, $web_user->pass_raw);
$this->assertTrue($result, t('Category list successfully retrieved.'));
if ($result !== FALSE && isset($result[0]['categoryId'])) {
$this->assertEqual($term_1, $result[0]['categoryId'], t('Category list verified.'));
}
// Test validation of category assignment.
// Set post categories.
$categories[] = array('categoryId' => $term_2);
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
$this->assertFalse($result, t('Post categories fail validation (attempt to post two when one is allowed).'));
// Change to required.
$this->updateVocabulary($vid, 'simpletest_vocab1', FALSE, TRUE);
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, array());
$this->assertFalse($result, t("Post categories fail validation (none posted when it's required)."));
// Change to allowing multiple, not required.
$this->updateVocabulary($vid, 'simpletest_vocab1', TRUE, FALSE);
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
$this->assertTrue($result, t('Post categories pass validation (multiple allowed).'));
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, array());
$this->assertTrue($result, t('Post categories pass validation (multiple allowed, none posted).'));
// Change to multiple, but required.
$this->updateVocabulary($vid, 'simpletest_vocab1', TRUE, TRUE);
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
$this->assertTrue($result, t('Post categories pass validation (multiple allowed).'));
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, array());
$this->assertFalse($result, t("Post categories fail validation (none posted when it's required)."));
// Try to add a non-existent term.
$categories[] = array('categoryId' => $term_2 + 1);
$result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
$this->assertFalse($result, t('Post categories fail validation (unknown term).'));
// Delete post.
$result = xmlrpc($local, 'blogger.deletePost', $appid, $nid, $web_user->name, $web_user->pass_raw, TRUE);
$this->assertTrue($result, t('Post successfully deleted.'));
}
/**
* Add taxonomy vocabulary.
*
* @param string $vocab
* Vocabulary name.
* @return integer
* The vocab ID.
*/
function addVocabulary($vocab) {
// Create a vocabulary.
$vocabulary = new stdClass();
$vocabulary->name = $vocab;
$vocabulary->description = $this->randomName();
$vocabulary->machine_name = $this->randomName();
$vocabulary->help = '';
$vocabulary->nodes = array('blog' => 'blog');
$vocabulary->weight = mt_rand(0, 10);
taxonomy_vocabulary_save($vocabulary);
return $vocabulary->vid;
}
/**
* Update a taxonomy vocabulary.
*
* @param $vocab
* Vocabulary name.
* @return integer
* The vocab ID.
*/
function updateVocabulary($vid, $vocab, $multiple = FALSE, $required = FALSE) {
$vocabulary = taxonomy_vocabulary_load($vid);
$vocabulary->name = $vocab;
$vocabulary->nodes = array('blog' => 'blog');
$vocabulary->multiple = $multiple;
$vocabulary->required = $required;
taxonomy_vocabulary_save($vocabulary);
}
/**
* Add a taxonomy term to vocabulary.
*
* @param integer $vid
* Vocabulary ID.
* @param string $term
* Term name.
* @return integer
* The Term ID.
*/
function addTerm($vid, $term_name) {
$term = new stdClass();
$term->name = $term_name;
$term->vid = $vid;
taxonomy_term_save($term);
return $term->tid;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment