View source
<?php
class Anonymouspublishingtest extends DrupalWebTestCase {
protected $user;
public static function getInfo() {
return array(
'name' => 'Anonymous Publishing CL',
'description' => 'Tests for the Anonymous Publishing CL module.',
'group' => 'Anonymous publishing',
);
}
public function setUp() {
parent::setUp(array(
'blog',
'anonymous_publishing',
'anonymous_publishing_cl',
));
variable_set('mail_system', array(
'default-system' => 'TestingMailSystem',
));
variable_set('anonymous_publishing_cl_types', array(
'blog' => 'blog',
'comment' => 'comment',
));
variable_set('anonymous_publishing_cl_options', array(
'sactivate' => 'sactivate',
'modmail' => 0,
'blockip' => 0,
'aregist' => 0,
));
variable_set('anonymous_publishing_cl_vrfypers', 0);
variable_set('anonymous_publishing_cl_alias', 0);
variable_set('anonymous_publishing_cl_flood', -1);
}
public function createNode($type, $email = NULL, $alias = NULL) {
$this
->drupalGet('/node/add/' . $type);
$edit = array();
$edit['title'] = 'Posting: ' . $this
->randomName(8);
$edit['body[und][0][value]'] = $this
->randomName(7) . ' ' . $this
->randomName(9) . '.';
if ($email) {
$edit['anonymous_publishing[email]'] = $email;
}
if ($alias) {
$edit['anonymous_publishing[alias]'] = $alias;
}
$this
->drupalPost('node/add/' . $type, $edit, t('Save'));
}
public function createComment($url, $email = NULL, $alias = NULL) {
$this
->drupalGet($url);
$edit = array();
$edit['subject'] = 'Comment: ' . $this
->randomName(8);
$edit['comment_body[und][0][value]'] = $this
->randomName(7) . ' ' . $this
->randomName(9) . '.';
if ($email) {
$edit['anonymous_publishing[email]'] = $email;
}
if ($alias) {
$edit['anonymous_publishing[alias]'] = $alias;
}
$this
->drupalPost($url, $edit, t('Save'));
}
public function checkPermission($type, $response) {
$this
->drupalGet('/node/add/' . $type);
$this
->assertText($response, 'A.1 (' . $type . '): The page content is present.');
}
public function createAnonContentNoEmail($type, $response) {
$this
->createNode($type);
$this
->assertText($response, 'A.2: The page content is present.');
}
public function createAnonContentWrongEmail($type, $response) {
$this
->createNode($type, $this
->randomName(5));
$this
->assertText($response, 'A.3: The page content is present.');
}
public function createAnonRequireAlias($type, $response) {
variable_set('anonymous_publishing_cl_alias', 3);
variable_set('anonymous_publishing_cl_requiredchar', 6);
$this
->createNode($type, 'emailadr@example.com');
$this
->assertText($response, 'A.4: The page content is present.');
}
public function createWithAlias($type, $response, $length) {
variable_set('anonymous_publishing_cl_alias', 3);
variable_set('anonymous_publishing_cl_requiredchar', 6);
$this
->createNode($type, 'emailadr@example.com', $this
->randomName($length));
$this
->assertText($response, 'A.5: The page content is present. (' . $response . ')');
}
public function apTestingActivation($akey, $response) {
$this
->drupalGet('/node/add/blog');
$this
->createNode('blog', 'blogger@example.com');
if (!empty($akey)) {
$options['query'] = array(
'akey' => $akey,
);
}
else {
$options = array();
}
$this
->drupalGet('/node/1/verify', $options);
$this
->assertText($response, 'A.6: Testing activation of node. (' . $response . ')');
}
public function createSaPeBoth($type) {
variable_set('anonymous_publishing_cl_vrfypers', 0);
variable_set('anonymous_publishing_cl_alias', 0);
$this
->drupalGet('/node/add/blog');
$email = 'blogger@example.com';
$this
->createNode('blog', $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'B.1: Node created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$this
->assertTrue(0 <= $lastmail, 'B.2: Got at least one mail', 'SaPeBoth');
$this
->assertEqual($mails[$lastmail]['subject'], 'Please activate your content on Drupal', 'B.2: Got activation mail [' . $lastmail . ']', 'SaPeBoth');
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Thanks for verifying', 'B.3: Node published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'B.4: Error: Stale activation key.');
$this
->createNode('blog', 'blogger@example.com');
$this
->assertText('Your email has been activated previously.', 'B.5: Node by returning contributor posted.');
$urlnode = substr($url, 0, strpos($url, '/verify'));
$email = 'commenter@example.com';
$this
->createComment($urlnode, $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'B.6: Comment created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Thanks for verifying', 'B.7: Comment published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'B.8: Error: Stale activation key.');
$this
->createComment($urlnode, 'commenter@example.com');
$this
->assertText('Your email has been activated previously.', 'B.9: Comment by returning contributor posted.');
}
public function createSaNpBoth($type) {
debug('Tests: C.1, C.2, C.3, C.4, C.5, C.6, C.7, C.8');
variable_set('anonymous_publishing_cl_vrfypers', 2);
variable_set('anonymous_publishing_cl_alias', 0);
$email = 'blogger2@example.com';
$this
->createNode('blog', $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Node created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Thanks for verifying', 'Node published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'Error: Stale activation key.');
$email = 'blogger2@example.com';
$this
->createNode('blog', $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Node created');
$urlnode = substr($url, 0, strpos($url, '/verify'));
$email = 'commenter2@example.com';
$this
->createComment($urlnode, $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Comment created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Thanks for verifying', 'Comment published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'Error: Stale activation key.');
$email = 'commenter@example.com';
$this
->createComment($urlnode, $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Node created');
}
public function createUnPeBoth($type) {
variable_set('anonymous_publishing_cl_vrfypers', 0);
variable_set('anonymous_publishing_cl_alias', 1);
$email = 'blogger3@example.com';
$this
->createNode('blog', $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'D.1: Node created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Thanks for verifying your e-mail', 'D.2: Node by published.');
$this
->assertText('Submitted by user', 'D.3: Persistent alias as byline.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'D.4: Error: Stale activation key.');
$this
->createNode('blog', 'blogger3@example.com');
$this
->assertText('Your email has been activated previously', 'D.5: Node by returning contributor posted.');
$this
->assertText('Submitted by user', 'D.6: Persistent alias as byline.');
$urlnode = substr($url, 0, strpos($url, '/verify'));
$email = 'commenter3@example.com';
$this
->createComment($urlnode, $email);
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'D.7: Comment created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('your comment has been published', 'D.8: Comment published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'D.9: Error: Stale activation key.');
$this
->createComment($urlnode, 'commenter3@example.com');
$this
->assertText('Your comment has been posted.', 'D.10: Comment by returning contributor posted.');
$this
->assertText('Submitted by user', 'D.11: Persistent alias as byline.');
}
public function createByPeBoth($type) {
debug('Tests: E.1, E.2, E.3, E.4, E.5, E.6, E.7, E.8');
variable_set('anonymous_publishing_cl_vrfypers', 0);
variable_set('anonymous_publishing_cl_alias', 2);
$email = 'blogger4@example.com';
$this
->createNode('blog', $email, 'John Bull');
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Node created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('Submitted by John Bull', 'Node by John Bull published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'Error: Stale activation key.');
$this
->createNode('blog', 'blogger4@example.com', 'Sitting Bull');
$this
->assertText('Submitted by Sitting Bull', 'Node by returning contributor Sitting Bull posted.');
$urlnode = substr($url, 0, strpos($url, '/verify'));
$email = 'commenter4@example.com';
$this
->createComment($urlnode, $email, 'John Bull');
$this
->assertText('You must also confirm that ' . $email . ' belongs to you.', 'Comment created');
$mails = $this
->drupalGetMails();
$lastmail = count($mails) - 1;
$url = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'http'));
$url = substr($url, 0, strpos($url, '/verify') + 7);
$path = substr($mails[$lastmail]['body'], strpos($mails[$lastmail]['body'], 'akey=') + 5);
$path = substr($path, 0, strpos($path, '.'));
$options['query'] = array(
'akey' => $path,
);
$this
->drupalGet($url, $options);
$this
->assertText('your comment has been published', 'Comment by John Bull published.');
$this
->drupalGet($url, $options);
$this
->assertText('Stale activation key', 'Error: Stale activation key.');
$this
->createComment($urlnode, 'commenter4@example.com', 'Crazy Horse');
$this
->assertText('Your comment has been posted.', 'Comment by returning contributor Crazy Horse posted.');
}
public function testAnonymouspublishing() {
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
'access content',
'create blog content',
'access comments',
'post comments',
'skip comment approval',
));
$this
->checkPermission('article', 'Access denied');
$this
->checkPermission('blog', 'Verification e-mail address:');
$this
->createAnonContentNoEmail('blog', 'Verification e-mail address: field is required.');
$this
->createAnonContentWrongEmail('blog', 'Please type in a valid e-mail address.');
$this
->createAnonRequireAlias('blog', 'Please enter a byline');
$this
->createWithAlias('blog', 'Please enter a byline', 5);
$this
->createWithAlias('blog', 'has been created', 6);
$this
->apTestingActivation('', 'No activation key present');
$this
->apTestingActivation('1234', 'Invalid activation key');
$this
->createSaPeBoth('blog');
$this
->createSaNpBoth('blog');
$this
->createUnPeBoth('blog');
$this
->createByPeBoth('blog');
}
}