Commit f0c731f2 authored by alexpott's avatar alexpott

Issue #2389455 by hussainweb, AjitS, Mile23, subhojit777, tibbsa, Ayesh:...

Issue #2389455 by hussainweb, AjitS, Mile23, subhojit777, tibbsa, Ayesh: Clean-up system module test members - ensure property definition and use of camelCase naming convention
parent 7cac6fa8
......@@ -18,8 +18,7 @@ class FormValuesTest extends AjaxTestBase {
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->drupalCreateUser(array('access content')));
}
/**
......
......@@ -47,8 +47,7 @@ protected function setUp() {
->save();
// Login a user who can create 'page' nodes.
$this->web_user = $this->drupalCreateUser(array('create page content'));
$this->drupalLogin($this->web_user);
$this->drupalLogin ($this->drupalCreateUser(array('create page content')));
}
/**
......
......@@ -14,9 +14,9 @@
*/
abstract class CacheTestBase extends WebTestBase {
protected $default_bin = 'render';
protected $default_cid = 'test_temporary';
protected $default_value = 'CacheTest';
protected $defaultBin = 'render';
protected $defaultCid = 'test_temporary';
protected $defaultValue = 'CacheTest';
/**
* Checks whether or not a cache entry exists.
......@@ -32,7 +32,7 @@ abstract class CacheTestBase extends WebTestBase {
*/
protected function checkCacheExists($cid, $var, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
$bin = $this->defaultBin;
}
$cached = \Drupal::cache($bin)->get($cid);
......@@ -54,13 +54,13 @@ protected function checkCacheExists($cid, $var, $bin = NULL) {
*/
protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
$bin = $this->defaultBin;
}
if ($cid == NULL) {
$cid = $this->default_cid;
$cid = $this->defaultCid;
}
if ($var == NULL) {
$var = $this->default_value;
$var = $this->defaultValue;
}
$this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message);
......@@ -78,10 +78,10 @@ protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin =
*/
function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
if ($bin == NULL) {
$bin = $this->default_bin;
$bin = $this->defaultBin;
}
if ($cid == NULL) {
$cid = $this->default_cid;
$cid = $this->defaultCid;
}
$cached = \Drupal::cache($bin)->get($cid);
......
......@@ -17,8 +17,8 @@
class ClearTest extends CacheTestBase {
protected function setUp() {
$this->default_bin = 'render';
$this->default_value = $this->randomMachineName(10);
$this->defaultBin = 'render';
$this->defaultValue = $this->randomMachineName(10);
parent::setUp();
}
......@@ -32,7 +32,7 @@ function testFlushAllCaches() {
$this->assertTrue($bins, 'Cache::getBins() returned bins to flush.');
foreach ($bins as $bin => $cache_backend) {
$cid = 'test_cid_clear' . $bin;
$cache_backend->set($cid, $this->default_value);
$cache_backend->set($cid, $this->defaultValue);
}
// Remove all caches then make sure that they are cleared.
......@@ -40,7 +40,7 @@ function testFlushAllCaches() {
foreach ($bins as $bin => $cache_backend) {
$cid = 'test_cid_clear' . $bin;
$this->assertFalse($this->checkCacheExists($cid, $this->default_value, $bin), format_string('All cache entries removed from @bin.', array('@bin' => $bin)));
$this->assertFalse($this->checkCacheExists($cid, $this->defaultValue, $bin), format_string('All cache entries removed from @bin.', array('@bin' => $bin)));
}
}
}
......@@ -56,9 +56,8 @@ protected function setUp() {
* Tests admin-defined formats in format_date().
*/
function testAdminDefinedFormatDate() {
// Create an admin user.
$this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($this->admin_user);
// Create and log in an admin user.
$this->drupalLogin($this->drupalCreateUser(array('administer site configuration')));
// Add new date format.
$edit = array(
......
......@@ -17,13 +17,13 @@
* @group Common
*/
class SizeUnitTest extends KernelTestBase {
protected $exact_test_cases;
protected $rounded_test_cases;
protected $exactTestCases;
protected $roundedTestCases;
protected function setUp() {
parent::setUp();
$kb = Bytes::KILOBYTE;
$this->exact_test_cases = array(
$this->exactTestCases = array(
'1 byte' => 1,
'1 KB' => $kb,
'1 MB' => $kb * $kb,
......@@ -34,12 +34,12 @@ protected function setUp() {
'1 ZB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb,
'1 YB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb * $kb,
);
$this->rounded_test_cases = array(
$this->roundedTestCases = array(
'2 bytes' => 2,
'1 MB' => ($kb * $kb) - 1, // rounded to 1 MB (not 1000 or 1024 kilobyte!)
round(3623651 / ($this->exact_test_cases['1 MB']), 2) . ' MB' => 3623651, // megabytes
round(67234178751368124 / ($this->exact_test_cases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
round(235346823821125814962843827 / ($this->exact_test_cases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
round(3623651 / ($this->exactTestCases['1 MB']), 2) . ' MB' => 3623651, // megabytes
round(67234178751368124 / ($this->exactTestCases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
round(235346823821125814962843827 / ($this->exactTestCases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
);
}
......@@ -47,7 +47,7 @@ protected function setUp() {
* Checks that format_size() returns the expected string.
*/
function testCommonFormatSize() {
foreach (array($this->exact_test_cases, $this->rounded_test_cases) as $test_cases) {
foreach (array($this->exactTestCases, $this->roundedTestCases) as $test_cases) {
foreach ($test_cases as $expected => $input) {
$this->assertEqual(
($result = format_size($input, NULL)),
......@@ -62,7 +62,7 @@ function testCommonFormatSize() {
* Cross-tests Bytes::toInt() and format_size().
*/
function testCommonParseSizeFormatSize() {
foreach ($this->exact_test_cases as $size) {
foreach ($this->exactTestCases as $size) {
$this->assertEqual(
$size,
($parsed_size = Bytes::toInt($string = format_size($size, NULL))),
......
......@@ -23,7 +23,7 @@ class SchemaTest extends KernelTestBase {
/**
* A global counter for table and field creation.
*/
var $counter;
protected $counter;
/**
* Tests database interactions.
......
......@@ -42,14 +42,14 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $referencing_entity;
protected $referencingEntity;
/**
* The entity instance not referencing the main entity.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $non_referencing_entity;
protected $nonReferencingEntity;
/**
* {@inheritdoc}
......@@ -96,8 +96,8 @@ protected function setUp() {
// Create a referencing and a non-referencing entity.
list(
$this->referencing_entity,
$this->non_referencing_entity,
$this->referencingEntity,
$this->nonReferencingEntity,
) = $this->createReferenceTestEntities($this->entity);
}
......@@ -305,8 +305,8 @@ protected function createReferenceTestEntities($referenced_entity) {
*/
public function testReferencedEntity() {
$entity_type = $this->entity->getEntityTypeId();
$referencing_entity_url = $this->referencing_entity->urlInfo('canonical');
$non_referencing_entity_url = $this->non_referencing_entity->urlInfo('canonical');
$referencing_entity_url = $this->referencingEntity->urlInfo('canonical');
$non_referencing_entity_url = $this->nonReferencingEntity->urlInfo('canonical');
$listing_url = Url::fromRoute('entity.entity_test.collection_referencing_entities', [
'entity_reference_field_name' => $entity_type . '_reference',
'referenced_entity_type' => $entity_type,
......@@ -335,7 +335,7 @@ public function testReferencedEntity() {
// Generate the cache tags for the (non) referencing entities.
$referencing_entity_cache_tags = Cache::mergeTags(
$this->referencing_entity->getCacheTags(),
$this->referencingEntity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
// Includes the main entity's cache tags, since this entity references it.
$this->entity->getCacheTags(),
......@@ -344,7 +344,7 @@ public function testReferencedEntity() {
['rendered']
);
$non_referencing_entity_cache_tags = Cache::mergeTags(
$this->non_referencing_entity->getCacheTags(),
$this->nonReferencingEntity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
['rendered']
);
......@@ -368,7 +368,7 @@ public function testReferencedEntity() {
// Verify a cache hit, but also the presence of the correct cache tags.
$this->verifyPageCache($referencing_entity_url, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags));
// Also verify the existence of an entity render cache entry.
$cache_keys = ['entity_view', 'entity_test', $this->referencing_entity->id(), 'full'];
$cache_keys = ['entity_view', 'entity_test', $this->referencingEntity->id(), 'full'];
$cid = $this->createCacheId($cache_keys, $entity_cache_contexts);
$redirected_cid = $this->createRedirectedCacheId($cache_keys, $entity_cache_contexts);
$this->verifyRenderCache($cid, $referencing_entity_cache_tags, $redirected_cid);
......@@ -378,7 +378,7 @@ public function testReferencedEntity() {
// Verify a cache hit, but also the presence of the correct cache tags.
$this->verifyPageCache($non_referencing_entity_url, 'HIT', Cache::mergeTags($non_referencing_entity_cache_tags, $page_cache_tags));
// Also verify the existence of an entity render cache entry.
$cache_keys = ['entity_view', 'entity_test', $this->non_referencing_entity->id(), 'full'];
$cache_keys = ['entity_view', 'entity_test', $this->nonReferencingEntity->id(), 'full'];
$cid = $this->createCacheId($cache_keys, $entity_cache_contexts);
$this->verifyRenderCache($cid, $non_referencing_entity_cache_tags);
......@@ -431,7 +431,7 @@ public function testReferencedEntity() {
// for every route except the ones for the non-referencing entity and the
// empty entity listing.
$this->pass("Test modification of referencing entity.", 'Debug');
$this->referencing_entity->save();
$this->referencingEntity->save();
$this->verifyPageCache($referencing_entity_url, 'MISS');
$this->verifyPageCache($listing_url, 'MISS');
$this->verifyPageCache($nonempty_entity_listing_url, 'HIT');
......@@ -447,7 +447,7 @@ public function testReferencedEntity() {
// Verify that after modifying the non-referencing entity, there is a cache
// miss only for the non-referencing entity route.
$this->pass("Test modification of non-referencing entity.", 'Debug');
$this->non_referencing_entity->save();
$this->nonReferencingEntity->save();
$this->verifyPageCache($referencing_entity_url, 'HIT');
$this->verifyPageCache($listing_url, 'HIT');
$this->verifyPageCache($empty_entity_listing_url, 'HIT');
......@@ -608,7 +608,7 @@ public function testReferencedEntity() {
// Verify cache hits.
$referencing_entity_cache_tags = Cache::mergeTags(
$this->referencing_entity->getCacheTags(),
$this->referencingEntity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
['rendered']
);
......@@ -655,7 +655,7 @@ protected function createCacheId(array $keys, array $contexts) {
* The redirected (post-bubbling) CID, if any.
*/
protected function createRedirectedCacheId(array $keys, array $contexts) {
$additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->referencing_entity);
$additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->referencingEntity);
if (count($additional_cache_contexts)) {
return $this->createCacheId($keys, Cache::mergeContexts($contexts, $additional_cache_contexts));
}
......
......@@ -35,17 +35,17 @@ class EntityFieldTest extends EntityUnitTestBase {
/**
* @var string
*/
protected $entity_name;
protected $entityName;
/**
* @var \Drupal\user\Entity\User
*/
protected $entity_user;
protected $entityUser;
/**
* @var string
*/
protected $entity_field_text;
protected $entityFieldText;
protected function setUp() {
parent::setUp();
......@@ -70,18 +70,18 @@ protected function setUp() {
* @return \Drupal\Core\Entity\EntityInterface
*/
protected function createTestEntity($entity_type) {
$this->entity_name = $this->randomMachineName();
$this->entity_user = $this->createUser();
$this->entity_field_text = $this->randomMachineName();
$this->entityName = $this->randomMachineName();
$this->entityUser = $this->createUser();
$this->entityFieldText = $this->randomMachineName();
// Pass in the value of the name field when creating. With the user
// field we test setting a field after creation.
$entity = entity_create($entity_type);
$entity->user_id->target_id = $this->entity_user->id();
$entity->name->value = $this->entity_name;
$entity->user_id->target_id = $this->entityUser->id();
$entity->name->value = $this->entityName;
// Set a value for the test field.
$entity->field_test_text->value = $this->entity_field_text;
$entity->field_test_text->value = $this->entityFieldText;
return $entity;
}
......@@ -111,9 +111,9 @@ protected function doTestReadWrite($entity_type) {
$this->assertTrue($entity->name instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', array('%entity_type' => $entity_type)));
$this->assertTrue($entity->name[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_name, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_name, $entity->name[0]->value, format_string('%entity_type: Name value can be read through list access.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->name->getValue(), array(0 => array('value' => $this->entity_name)), format_string('%entity_type: Plain field value returned.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityName, $entity->name[0]->value, format_string('%entity_type: Name value can be read through list access.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->name->getValue(), array(0 => array('value' => $this->entityName)), format_string('%entity_type: Plain field value returned.', array('%entity_type' => $entity_type)));
// Change the name.
$new_name = $this->randomMachineName();
......@@ -129,8 +129,8 @@ protected function doTestReadWrite($entity_type) {
$this->assertTrue($entity->user_id instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', array('%entity_type' => $entity_type)));
$this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
// Change the assigned user by entity.
$new_user1 = $this->createUser();
......@@ -241,28 +241,28 @@ protected function doTestReadWrite($entity_type) {
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Access the text field and test updating.
$this->assertEqual($entity->field_test_text->value, $this->entity_field_text, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->field_test_text->value, $this->entityFieldText, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
$new_text = $this->randomMachineName();
$entity->field_test_text->value = $new_text;
$this->assertEqual($entity->field_test_text->value, $new_text, format_string('%entity_type: Updated text field can be read.', array('%entity_type' => $entity_type)));
// Test creating the entity by passing in plain values.
$this->entity_name = $this->randomMachineName();
$name_item[0]['value'] = $this->entity_name;
$this->entity_user = $this->createUser();
$user_item[0]['target_id'] = $this->entity_user->id();
$this->entity_field_text = $this->randomMachineName();
$text_item[0]['value'] = $this->entity_field_text;
$this->entityName = $this->randomMachineName();
$name_item[0]['value'] = $this->entityName;
$this->entityUser = $this->createUser();
$user_item[0]['target_id'] = $this->entityUser->id();
$this->entityFieldText = $this->randomMachineName();
$text_item[0]['value'] = $this->entityFieldText;
$entity = entity_create($entity_type, array(
'name' => $name_item,
'user_id' => $user_item,
'field_test_text' => $text_item,
));
$this->assertEqual($this->entity_name, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_field_text, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
// Tests copying field values by assigning the TypedData objects.
$entity2 = $this->createTestEntity($entity_type);
......@@ -374,9 +374,9 @@ protected function doTestSave($entity_type) {
$this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_field_text, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
}
/**
......@@ -550,10 +550,10 @@ protected function doTestDataStructureInterfaces($entity_type) {
$target_strings = array(
$entity->uuid->value,
'en',
$this->entity_name,
$this->entityName,
// Bundle name.
$entity->bundle(),
$this->entity_field_text,
$this->entityFieldText,
// Field format.
NULL,
);
......
......@@ -35,14 +35,14 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
*
* @var string
*/
protected $field_name;
protected $fieldName;
/**
* The untranslatable test field name.
*
* @var string
*/
protected $untranslatable_field_name;
protected $untranslatableFieldName;
public static $modules = array('language', 'entity_test');
......@@ -67,35 +67,35 @@ protected function setUp() {
$this->state->set('entity_test.translation', TRUE);
// Create a translatable test field.
$this->field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
$this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
// Create an untranslatable test field.
$this->untranslatable_field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
$this->untranslatableFieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
// Create field fields in all entity variations.
foreach (entity_test_entity_types() as $entity_type) {
entity_create('field_storage_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => $entity_type,
'type' => 'text',
'cardinality' => 4,
))->save();
entity_create('field_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => $entity_type,
'bundle' => $entity_type,
'translatable' => TRUE,
))->save();
$this->field[$entity_type] = FieldConfig::load($entity_type . '.' . $entity_type . '.' . $this->field_name);
$this->field[$entity_type] = FieldConfig::load($entity_type . '.' . $entity_type . '.' . $this->fieldName);
entity_create('field_storage_config', array(
'field_name' => $this->untranslatable_field_name,
'field_name' => $this->untranslatableFieldName,
'entity_type' => $entity_type,
'type' => 'text',
'cardinality' => 4,
))->save();
entity_create('field_config', array(
'field_name' => $this->untranslatable_field_name,
'field_name' => $this->untranslatableFieldName,
'entity_type' => $entity_type,
'bundle' => $entity_type,
'translatable' => FALSE,
......@@ -125,7 +125,7 @@ protected function setUp() {
* The type of the entity fields are attached to.
*/
protected function toggleFieldTranslatability($entity_type, $bundle) {
$fields = array($this->field_name, $this->untranslatable_field_name);
$fields = array($this->fieldName, $this->untranslatableFieldName);
foreach ($fields as $field_name) {
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
$translatable = !$field->isTranslatable();
......
......@@ -29,10 +29,10 @@ protected function setUp() {
parent::setUp();
// Create and login user.
$this->web_user = $this->drupalCreateUser(array(
$this->webUser = $this->drupalCreateUser(array(
'administer entity_test content',
));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
}
/**
......
......@@ -27,10 +27,7 @@ protected function setUp() {
parent::setUp();
// Create and login user.
$this->web_user = $this->drupalCreateUser(array(
'administer permissions',
));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->drupalCreateUser(array('administer permissions')));
}
/**
......
......@@ -24,14 +24,21 @@ class EntityRevisionsTest extends WebTestBase {
*/
public static $modules = array('entity_test');
/**
* A user with permission to administer entity_test content.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected function setUp() {
parent::setUp();
// Create and login user.
$this->web_user = $this->drupalCreateUser(array(
$this->webUser = $this->drupalCreateUser(array(
'administer entity_test content',
));
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
}
/**
......@@ -56,7 +63,7 @@ protected function assertRevisions($entity_type) {
// Create initial entity.
$entity = entity_create($entity_type, array(
'name' => 'foo',
'user_id' => $this->web_user->id(),
'user_id' => $this->webUser->id(),
));
$entity->field_test_text->value = 'bar';
$entity->save();
......
......@@ -52,22 +52,22 @@ protected function doTestEntityLanguageMethods($entity_type) {
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Set the value in default language.
$entity->set($this->field_name, array(0 => array('value' => 'default value')));
$entity->set($this->fieldName, array(0 => array('value' => 'default value')));
// Get the value.
$field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get($this->field_name);
$field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get($this->fieldName);
$this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type)));
$this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Set the value in a certain language. As the entity is not
// language-specific it should use the default language and so ignore the
// specified language.
$entity->getTranslation($this->langcodes[1])->set($this->field_name, array(0 => array('value' => 'default value2')));
$this->assertEqual($entity->get($this->field_name)->value, 'default value2', format_string('%entity_type: Untranslated value updated.', array('%entity_type' => $entity_type)));
$entity->getTranslation($this->langcodes[1])->set($this->fieldName, array(0 => array('value' => 'default value2')));
$this->assertEqual($entity->get($this->fieldName)->value, 'default value2', format_string('%entity_type: Untranslated value updated.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Test getting a field value using a specific language for a not
// language-specific entity.
$field = $entity->getTranslation($this->langcodes[1])->get($this->field_name);
$field = $entity->getTranslation($this->langcodes[1])->get($this->fieldName);
$this->assertEqual($field->value, 'default value2', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type)));
$this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
......@@ -75,25 +75,25 @@ protected function doTestEntityLanguageMethods($entity_type) {
// translating it.
$default_langcode = $this->langcodes[0];
$entity->{$langcode_key}->value = $default_langcode;
$entity->{$this->field_name} = array();
$entity->{$this->fieldName} = array();
$this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), format_string('%entity_type: Entity language retrieved.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Set the value in default language.
$entity->set($this->field_name, array(0 => array('value' => 'default value')));
$entity->set($this->fieldName, array(0 => array('value' => 'default value')));
// Get the value.
$field = $entity->get($this->field_name);
$field = $entity->get($this->fieldName);
$this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type)));
$this->assertEqual($field->getLangcode(), $default_langcode, format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Set a translation.
$entity->getTranslation($this->langcodes[1])->set($this->field_name, array(0 => array('value' => 'translation 1')));
$field = $entity->getTranslation($this->langcodes[1])->{$this->field_name};
$entity->getTranslation($this->langcodes[1])->set($this->fieldName, array(0 => array('value' => 'translation 1')));
$field = $entity->getTranslation($this->langcodes[1])->{$this->fieldName};
$this->assertEqual($field->value, 'translation 1', format_string('%entity_type: Translated value set.', array('%entity_type' => $entity_type)));
$this->assertEqual($field->getLangcode(), $this->langcodes[1], format_string('%entity_type: Field object has the expected langcode.', array('%entity_type' => $entity_type)));
// Make sure the untranslated value stays.
$field = $entity->get($this->field_name);
$field = $entity->get($this->fieldName);
$this->assertEqual($field->value, 'default value', 'Untranslated value stays.');
$this->assertEqual($field->getLangcode(), $default_langcode, 'Untranslated value has the expected langcode.');
......@@ -101,11 +101,11 @@ protected function doTestEntityLanguageMethods($entity_type) {
$this->assertEqual($entity->getTranslationLanguages(FALSE), $translations, 'Translations retrieved.');
// Try to get a not available translation.
$this->assertNull($entity->getTranslation($this->langcodes[2])->get($this->field_name)->value, format_string('%entity_type: A translation that is not available is NULL.', array('%entity_type' => $entity_type)));
$this->assertNull($entity->getTranslation($this->langcodes[2])->get($this->fieldName)->value, format_string('%entity_type: A translation that is not available is NULL.', array('%entity_type' => $entity_type)));
// Try to get a value using an invalid language code.
try {
$entity->getTranslation('invalid')->get($this->field_name)->value;
$entity->getTranslation('invalid')->get($this->fieldName)->value;
$this->fail('Getting a translation for an invalid language is NULL.');
}
catch (\InvalidArgumentException $e) {
......@@ -114,7 +114,7 @@ protected function doTestEntityLanguageMethods($entity_type) {
// Try to set a value using an invalid language code.
try {
$entity->getTranslation('invalid')->set($this->field_name, NULL);
$entity->getTranslation('invalid')->set($this->fieldName, NULL);
$this->fail(format_string('%entity_type: Setting a translation for an invalid language throws an exception.', array('%entity_type' => $entity_type)));
}
catch (\InvalidArgumentException $e) {
......@@ -278,7 +278,7 @@ protected function doTestMultilingualProperties($entity_type) {
// Test mixed property and field conditions.
$entity = entity_load($entity_type, reset($result), TRUE);
$field_value = $this->randomString();
$entity->getTranslation($langcode)->set($this->field_name, array(array('value' => $field_value)));
$entity->getTranslation($langcode)->set($this->fieldName, array(array('value' => $field_value)));
$entity->save();
$query = \Drupal::entityQuery($entity_type);
$default_langcode_group = $query->andConditionGroup()
......@@ -286,7 +286,7 @@ protected function doTestMultilingualProperties($entity_type) {
->condition('name', $properties[$default_langcode]['name'][0], '=', $default_langcode);
$langcode_group = $query->andConditionGroup()
->condition('name', $properties[$langcode]['name'][0], '=', $langcode)
->condition("$this->field_name.value", $field_value, '=', $langcode);
->condition("$this->fieldName.value", $field_value, '=', $langcode);
$result = $query
->condition($langcode_key, $default_langcode)
->condition($default_langcode_group)
......@@ -681,11 +681,11 @@ protected function doTestLanguageChange($entity_type) {
// translatability.
$values = array(
$langcode_key => $langcode,
$this->field_name => $this->randomMachineName(),
$this->untranslatable_field_name => $this->randomMachineName(),
$this->fieldName => $this->randomMachineName(),
$this->untranslatableFieldName => $this->randomMachineName(),
);
$entity = $controller->create($values);
foreach (array($this->field_name, $this->untranslatable_field_name) as $field_name) {
foreach (array($this->fieldName, $this->untranslatableFieldName) as $field_name) {