You are here

public function TermstatusSafeguardTestCase::testFirstUseSafeguard in Taxonomy Term Status 7

Tests the first-use-safeguard mechanism.

File

./termstatus.test, line 77
Tests for termstatus.module

Class

TermstatusSafeguardTestCase
Tests the mechanism preventing terms from being unpublished.

Code

public function testFirstUseSafeguard() {
  $vocabulary = $this
    ->createVocabulary();
  $term = $this
    ->createTerm($vocabulary);
  $this
    ->drupalGet('taxonomy/term/' . $term->tid);
  $this
    ->assertResponse(200, 'Taxonomy term page should be accessible.');
  $this
    ->assertText($term->name, 'Page should contain the term name.');

  // Make sure variable termstatus_enable does not exist.
  variable_del('termstatus_enable');
  module_enable(array(
    'termstatus',
  ));

  // Reset/rebuild all data structures after enabling the modules.
  $this
    ->resetAll();

  // Safeguard against unpublished terms: Variable termstatus_enable should
  // be set to FALSE.
  $this
    ->assertIdentical(FALSE, variable_get('termstatus_enable'), 'Variable termstatus_enable should be set to false after module is enabled');

  // Ensure that the term is still accessible - even if its publishing state
  // has not changed yet.
  $this
    ->drupalGet('taxonomy/term/' . $term->tid);
  $this
    ->assertResponse(200, 'Taxonomy term page should still be accessible after module was enabled.');
  $this
    ->assertText($term->name, 'Page should contain the term name.');

  // Ensure that a warning is reported through hook_requirements.
  module_load_install('termstatus');
  $termstatus_requirements = module_invoke('termstatus', 'requirements', 'runtime');
  $this
    ->assertEqual(1, count($termstatus_requirements), 'Should report one requirement record');
  $req = reset($termstatus_requirements);
  $this
    ->assertEqual($req['severity'], REQUIREMENT_WARNING, 'Severity of requirement record should be "warning".');

  // Turn on the variable and test whether the requirements are updated.
  variable_set('termstatus_enable', TRUE);
  $termstatus_requirements = module_invoke('termstatus', 'requirements', 'runtime');
  $this
    ->assertEqual(1, count($termstatus_requirements), 'Should report one requirement record');
  $req = reset($termstatus_requirements);
  $this
    ->assertEqual($req['severity'], REQUIREMENT_OK, 'Severity of requirement record should be "ok" after "termstatus_enable" variable has been manipulated.');
}