You are here

function BiblioKeywordUnitTest::testBiblioExplodeKeywords in Bibliography Module 7.2

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

File

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

Class

BiblioKeywordUnitTest
Unit tests for keyword functions.

Code

function testBiblioExplodeKeywords() {
  $keywords = array();
  $exploded = array();
  $words = array();
  $sep = variable_get('biblio_keyword_sep', ',');
  $wrong_sep = $sep == ',' ? ';' : ',';
  for ($i = 0; $i < 4; $i++) {
    $words[] = $this
      ->randomName();
  }
  $string = implode($sep, $words);
  $exploded = biblio_explode_keywords($string);
  $this
    ->assertIdentical($words, $exploded, 'Exploded keyword string with correct separator');
  $string = implode($wrong_sep, $words);
  $exploded = biblio_explode_keywords($string);
  $this
    ->assertNotIdentical($words, $exploded, 'Tried to explode keyword string with incorrect separator');
  $words[] = '"' . 'word1' . $sep . ' word2' . '"';
  $string = implode($sep, $words);
  $exploded = biblio_explode_keywords($string);
  $words[4] = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $words[4])));

  // strip the quotes becuase that's the way it comes back
  $this
    ->assertEqual($words, $exploded, "Exploded a keyword string which contains and escaped separator");
}