You are here

public function CertificateTestCase::testCertificateMapping in Certificate 8.3

Same name and namespace in other branches
  1. 6.2 certificate.test \CertificateTestCase::testCertificateMapping()
  2. 7.3 certificate.test \CertificateTestCase::testCertificateMapping()
  3. 7.2 certificate.test \CertificateTestCase::testCertificateMapping()
  4. 3.x certificate.test \CertificateTestCase::testCertificateMapping()

Test that the user receives the correct certificate.

File

./certificate.test, line 55
certificate.test

Class

CertificateTestCase
Tests for Certificate.

Code

public function testCertificateMapping() {
  $activity_node = $this
    ->drupalCreateNode(array(
    'type' => $this->contentType->type,
  ));
  $content = array(
    'title' => 'Test Certificate',
    'name' => 'test_certificate',
    'orientation' => 'portrait',
    'certificate_body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'My Certificate Body 1',
        ),
      ),
    ),
    'type' => 'certificate',
  );
  $certificate = entity_create('certificate', $content);
  entity_save('certificate', $certificate);

  // We give them the permission because we have to preview it here.
  $u1 = $this
    ->drupalCreateUser(array(
    'administer certificates',
  ));
  $firstletter = $u1->name[0];
  $this
    ->drupalLogin($u1);
  $GLOBALS['certificate_ok'] = TRUE;
  $this
    ->drupalGet("node/{$activity_node->nid}/certificate", array(
    'query' => array(
      'certificate_ok' => 1,
      'preview' => TRUE,
    ),
  ));
  $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
    ->assertText('Sorry, there is no certificate available.', 'Found no certificate available text.');

  // Map the first letter of the user's name to the certificate.
  certificate_update_node_mappings($activity_node->nid, array(
    'firstletter' => array(
      $firstletter => $certificate->name,
    ),
  ));
  $this
    ->drupalGet("node/{$activity_node->nid}/certificate", array(
    'query' => array(
      'certificate_ok' => 1,
      'preview' => TRUE,
    ),
  ));
  $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.');
  $this
    ->assertText("My Certificate Body 1", "Saw certificate body.");
}