View source
<?php
class CertificateTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Certificate',
'description' => 'Ensure that the Certificate module functions properly.',
'group' => 'Certificate',
);
}
public function setUp() {
parent::setUp(array(
'certificate',
'certificate_test',
));
$this->contentType = $this
->drupalCreateContentType(array(
'type' => 'certificate_activity',
));
variable_set("certificate_certifiable_" . $this->contentType->type, TRUE);
}
public function testCertificateAccess() {
$u1 = $this
->drupalCreateUser();
$activity_node = $this
->drupalCreateNode(array(
'type' => $this->contentType->type,
));
$result = certificate_can_access_certificate($activity_node, $u1);
$this
->assertTrue($result !== TRUE, 'User cannot access certificate.');
$this
->assertTrue($result == 'Custom access denied message.', 'Error message matched module provided message.');
$GLOBALS['certificate_ok'] = TRUE;
$result = certificate_can_access_certificate($activity_node, $u1, TRUE);
$this
->assertTrue($result === TRUE, 'User can access certificate.');
}
public function testCertificateMapping() {
$activity_node = $this
->drupalCreateNode(array(
'type' => $this->contentType->type,
));
$certificate = $this
->drupalCreateNode(array(
'type' => 'certificate',
));
$u1 = $this
->drupalCreateUser();
$firstletter = $u1->name[0];
$this
->drupalLogin($u1);
$GLOBALS['certificate_ok'] = TRUE;
$this
->drupalGet("node/{$activity_node->nid}/certificate", array(
'query' => array(
'certificate_ok' => 1,
),
));
$this
->assertNoResponse(403, 'Did not get access denied.');
$this
->assertNoText('Custom access denied message.', 'Did not find moduled provided access denied message on certificate page.');
$this
->assertText('Sorry, there is no certificate available.', 'Found no certificate available text.');
certificate_update_node_mappings($activity_node->nid, array(
'firstletter' => array(
$firstletter => $certificate->nid,
),
));
$this
->drupalGet("node/{$activity_node->nid}/certificate", array(
'query' => array(
'certificate_ok' => 1,
),
));
$this
->assertNoResponse(403, 'Did not get access denied.');
$this
->assertNoText('Custom access denied message.', 'Did not find module provided access denied message on certificate page.');
$this
->assertNoText('Sorry, there is no certificate available.', 'User received certificate.');
}
function testCertificateTemplates() {
$account = $this
->drupalCreateUser(array(
'administer certificates',
));
$node = $this
->drupalCreateNode(array(
'title' => 'My test certifiable type',
));
$certificate = $this
->drupalCreateNode(array(
'type' => 'certificate',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => '[node:title][user:name]',
),
),
),
));
$firstletter = $account->name[0];
certificate_update_node_mappings($node->nid, array(
'firstletter' => array(
$firstletter => $certificate->nid,
),
));
$this
->drupalLogin($account);
$this
->drupalGet("node/{$node->nid}/certificate?preview");
$this
->assertText('My test certifiable type', "Saw node title.");
$this
->assertText($account->name, "Saw user name.");
}
}