Issue #1848904 by andypost, tim.plunkett: Bundles cannot be specified in Entity Translation tests.
parent
f13c337b54
commit
e3d9711e5c
|
@ -19,6 +19,13 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The vocabulary used for creating terms.
|
||||
*
|
||||
* @var \Drupal\taxonomy\Plugin\Core\Entity\Vocabulary
|
||||
*/
|
||||
protected $vocabulary;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -51,7 +58,7 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
parent::setupBundle();
|
||||
|
||||
// Create a vocabulary.
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
'name' => $this->bundle,
|
||||
'description' => $this->randomName(),
|
||||
'machine_name' => $this->bundle,
|
||||
|
@ -59,7 +66,7 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
'help' => '',
|
||||
'weight' => mt_rand(0, 10),
|
||||
));
|
||||
taxonomy_vocabulary_save($vocabulary);
|
||||
$this->vocabulary->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,13 +79,16 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
/**
|
||||
* Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::createEntity().
|
||||
*/
|
||||
protected function createEntity($values, $langcode, $vocabulary_name = NULL) {
|
||||
if (!isset($vocabulary_name)) {
|
||||
$vocabulary_name = $this->bundle;
|
||||
protected function createEntity($values, $langcode, $bundle_name = NULL) {
|
||||
if (isset($bundle_name)) {
|
||||
$vocabulary = taxonomy_vocabulary_machine_name_load($bundle_name);
|
||||
}
|
||||
$vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name);
|
||||
else {
|
||||
$vocabulary = $this->vocabulary;
|
||||
}
|
||||
// Term needs vid to be saved.
|
||||
$values['vid'] = $vocabulary->id();
|
||||
return parent::createEntity($values, $langcode);
|
||||
return parent::createEntity($values, $langcode, $bundle_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +120,7 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer taxonomy', 'translate any entity'));
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
$translatable_vocabulary_name = taxonomy_vocabulary_machine_name_load($this->bundle)->name;
|
||||
$translatable_vocabulary_name = $this->vocabulary->name;
|
||||
$translatable_tid = $this->createEntity(array(), $this->langcodes[0]);
|
||||
|
||||
// Create an untranslatable vocabulary.
|
||||
|
@ -122,7 +132,7 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
|||
'help' => '',
|
||||
'weight' => mt_rand(0, 10),
|
||||
));
|
||||
taxonomy_vocabulary_save($untranslatable_vocabulary);
|
||||
$untranslatable_vocabulary->save();
|
||||
|
||||
$untranslatable_vocabulary_name = $untranslatable_vocabulary->name;
|
||||
$untranslatable_tid = $this->createEntity(array(), $this->langcodes[0], $untranslatable_vocabulary_name);
|
||||
|
|
|
@ -231,16 +231,19 @@ abstract class EntityTranslationUITest extends WebTestBase {
|
|||
* An array of initial values for the entity.
|
||||
* @param string $langcode
|
||||
* The initial language code of the entity.
|
||||
* @param string $bundle_name
|
||||
* (optional) The entity bundle, if the entity uses bundles. Defaults to
|
||||
* NULL. If left NULL, $this->bundle will be used.
|
||||
*
|
||||
* @return
|
||||
* The entity id.
|
||||
*/
|
||||
protected function createEntity($values, $langcode) {
|
||||
protected function createEntity($values, $langcode, $bundle_name = NULL) {
|
||||
$entity_values = $values;
|
||||
$entity_values['langcode'] = $langcode;
|
||||
$info = entity_get_info($this->entityType);
|
||||
if (!empty($info['entity_keys']['bundle'])) {
|
||||
$entity_values[$info['entity_keys']['bundle']] = $this->bundle;
|
||||
$entity_values[$info['entity_keys']['bundle']] = $bundle_name ?: $this->bundle;
|
||||
}
|
||||
$controller = entity_get_controller($this->entityType);
|
||||
if (!($controller instanceof DatabaseStorageControllerNG)) {
|
||||
|
@ -280,7 +283,7 @@ abstract class EntityTranslationUITest extends WebTestBase {
|
|||
/**
|
||||
* Returns the translation object to use to retrieve the translated values.
|
||||
*
|
||||
* @param \Drupal\Core\Enitity\EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity being tested.
|
||||
* @param string $langcode
|
||||
* The language code identifying the translation to be retrieved.
|
||||
|
|
Loading…
Reference in New Issue