Test CRUD API.
function testStringCRUDAPI() {
// Create source string.
$source = $this
->buildSourceString();
$source
->save();
$this
->assertTrue($source->lid, format_string('Successfully created string %string', array(
'%string' => $source->source,
)));
// Load strings by lid and source.
$string1 = $this->storage
->findString(array(
'lid' => $source->lid,
));
$this
->assertEqual($source, $string1, 'Successfully retrieved string by identifier.');
$string2 = $this->storage
->findString(array(
'source' => $source->source,
'context' => $source->context,
));
$this
->assertEqual($source, $string2, 'Successfully retrieved string by source and context.');
$string3 = $this->storage
->findString(array(
'source' => $source->source,
'context' => '',
));
$this
->assertFalse($string3, 'Cannot retrieve string with wrong context.');
// Check version handling and updating.
$this
->assertEqual($source->version, 'none', 'String originally created without version.');
$string = $this->storage
->findTranslation(array(
'lid' => $source->lid,
));
$this
->assertEqual($string->version, VERSION, 'Checked and updated string version to Drupal version.');
// Create translation and find it by lid and source.
$langcode = 'es';
$translation = $this
->createTranslation($source, $langcode);
$this
->assertEqual($translation->customized, LOCALE_NOT_CUSTOMIZED, 'Translation created as not customized by default.');
$string1 = $this->storage
->findTranslation(array(
'language' => $langcode,
'lid' => $source->lid,
));
$this
->assertEqual($string1->translation, $translation->translation, 'Successfully loaded translation by string identifier.');
$string2 = $this->storage
->findTranslation(array(
'language' => $langcode,
'source' => $source->source,
'context' => $source->context,
));
$this
->assertEqual($string2->translation, $translation->translation, 'Successfully loaded translation by source and context.');
$translation
->setCustomized()
->save();
$translation = $this->storage
->findTranslation(array(
'language' => $langcode,
'lid' => $source->lid,
));
$this
->assertEqual($translation->customized, LOCALE_CUSTOMIZED, 'Translation successfully marked as customized.');
// Delete translation.
$translation
->delete();
$deleted = $this->storage
->findTranslation(array(
'language' => $langcode,
'lid' => $source->lid,
));
$this
->assertFalse(isset($deleted->translation), 'Successfully deleted translation string.');
// Create some translations and then delete string and all of its translations.
$lid = $source->lid;
$translations = $this
->createAllTranslations($source);
$search = $this->storage
->getTranslations(array(
'lid' => $source->lid,
));
$this
->assertEqual(count($search), 3, 'Created and retrieved all translations for our source string.');
$source
->delete();
$string = $this->storage
->findString(array(
'lid' => $lid,
));
$this
->assertFalse($string, 'Successfully deleted source string.');
$deleted = $search = $this->storage
->getTranslations(array(
'lid' => $lid,
));
$this
->assertFalse($deleted, 'Successfully deleted all translation strings.');
}