You are here

function BiblioKeywordUnitTest::testBiblioGetKeywordByName in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 tests/keyword.test \BiblioKeywordUnitTest::testBiblioGetKeywordByName()

File

tests/keyword.test, line 57
Tests for keyword functions.

Class

BiblioKeywordUnitTest
Unit tests for keyword functions.

Code

function testBiblioGetKeywordByName() {
  $keyword = $this
    ->createKeyword();

  // Load the term with the exact name.
  $word = biblio_get_keyword_by_name($keyword['word']);
  $this
    ->assertEqual($word->word, $keyword['word'], t('Keyword loaded using exact name.'));

  // Load the term with space concatenated.
  $word = biblio_get_keyword_by_name('  ' . $keyword['word'] . '   ');
  $this
    ->assertEqual($word->word, trim('  ' . $keyword['word'] . '   '), t('Keyword loaded with extra whitespace.'));

  // Load the term with name uppercased.
  $word = biblio_get_keyword_by_name(strtoupper($keyword['word']));
  $this
    ->assertEqual($word->word, $keyword['word'], t('Keyword loaded with uppercased name.'));

  // Load the term with name lowercased.
  $word = biblio_get_keyword_by_name(strtolower($keyword['word']));
  $this
    ->assertEqual($word->word, $keyword['word'], t('Keyword loaded with lowercased name.'));

  // Try to load an invalid term name.
  $word = biblio_get_keyword_by_name('Banana');
  $this
    ->assertFalse($word, t('Tried to load an invalid keyword'));

  // Try to load the term using a substring of the name.
  $word = biblio_get_keyword_by_name(drupal_substr($keyword['word'], 2));
  $this
    ->assertFalse($word, t('Tried to load a keyword using a substring of the word'));
}