diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 5c6e8b3..b9de0b6 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\Schema\Ignore; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\PrimitiveInterface; use Drupal\Core\TypedData\Type\FloatInterface; use Drupal\Core\TypedData\Type\IntegerInterface; @@ -184,6 +185,10 @@ protected function castValue($key, $value) { $this->validateValue($key, $value); return $value; } + // Support translation wrappers. + if ($value instanceof TranslationWrapper) { + $value = (string) $value; + } if (is_scalar($value) || $value === NULL) { if ($element && $element instanceof PrimitiveInterface) { // Special handling for integers and floats since the configuration diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 128d21d..e1e236b 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -711,7 +711,7 @@ public function getAllBundleInfo() { foreach ($this->getDefinitions() as $type => $entity_type) { // If no bundles are provided, use the entity type name and label. if (!isset($this->bundleInfo[$type])) { - $this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel(); + $this->bundleInfo[$type][$type]['label'] = $entity_type->get('label'); } } $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo); diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php index 0c80fcf..254a7ca 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php @@ -82,7 +82,8 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Add definitions for each entity type and bundle. foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { $this->derivatives[$entity_type_id] = array( - 'label' => $entity_type->getLabel(), + // Use get('label') to not get the already translated wrapper. + 'label' => $entity_type->get('label'), 'constraints' => array('EntityType' => $entity_type_id), ) + $base_plugin_definition; diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index dac6584..97f9dd2 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -1403,7 +1403,7 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st $column_schema = $field_schema['columns'][$field_column_name]; $schema['fields'][$schema_field_name] = $column_schema; - $schema['fields'][$schema_field_name]['description'] = $field_description; + $schema['fields'][$schema_field_name]['description'] = (string) $field_description; // Only entity keys are required. $keys = $this->entityType->getKeys() + array('langcode' => 'langcode'); // The label is an entity key, but label fields are not necessarily diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 20a6506..c65f3d4 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -370,6 +370,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // Remove any potential cache bins provided by the module. $this->removeCacheBins($module); + // Update the kernel to exclude the uninstalled modules. + $this->updateKernel($module_filenames); + // Clear the static cache of system_rebuild_module_data() to pick up the // new module, since it merges the installation status of modules into // its statically cached list. @@ -379,9 +382,6 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); \Drupal::service('router.builder_indicator')->setRebuildNeeded(); - // Update the kernel to exclude the uninstalled modules. - $this->updateKernel($module_filenames); - // Update the theme registry to remove the newly uninstalled module. drupal_theme_rebuild(); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php index 2fb8242..d421d21 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php @@ -7,11 +7,13 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\OptionsProviderInterface; use Drupal\Core\TypedData\DataDefinition; @@ -33,8 +35,8 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface { */ public static function defaultStorageSettings() { return array( - 'on_label' => t('On'), - 'off_label' => t('Off'), + 'on_label' => new TranslationWrapper('On'), + 'off_label' => new TranslationWrapper('Off'), ) + parent::defaultStorageSettings(); } @@ -42,8 +44,10 @@ public static function defaultStorageSettings() { * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { + // Use TranslationWrapper as those can be called during early bootstrap, + // before the translation system is ready. $properties['value'] = DataDefinition::create('boolean') - ->setLabel(t('Boolean value')); + ->setLabel(new TranslationWrapper('Boolean value')); return $properties; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php index 961eb67..9c81c10 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php @@ -7,9 +7,11 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataReferenceDefinition; @@ -34,12 +36,14 @@ class LanguageItem extends FieldItemBase { * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { + // Use TranslationWrapper as those can be called during early bootstrap, + // before the translation system is ready. $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Language code')); + ->setLabel(new TranslationWrapper('Language code')); $properties['language'] = DataReferenceDefinition::create('language') - ->setLabel(t('Language object')) - ->setDescription(t('The referenced language')) + ->setLabel(new TranslationWrapper('Language object')) + ->setDescription(new TranslationWrapper('The referenced language')) // The language object is retrieved via the language code. ->setComputed(TRUE) ->setReadOnly(FALSE); diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php index ede2854..b4187e6 100644 --- a/core/lib/Drupal/Core/Session/AccountInterface.php +++ b/core/lib/Drupal/Core/Session/AccountInterface.php @@ -48,30 +48,6 @@ public function getRoles($exclude_locked_roles = FALSE); public function hasPermission($permission); /** - * Returns the session ID. - * - * @return string|null - * The session ID or NULL if this user does not have an active session. - */ - public function getSessionId(); - - /** - * Returns the secure session ID. - * - * @return string|null - * The session ID or NULL if this user does not have an active secure session. - */ - public function getSecureSessionId(); - - /** - * Returns the session data. - * - * @return array - * Array with the session data that belongs to this object. - */ - public function getSessionData(); - - /** * Returns TRUE if the account is authenticated. * * @return bool @@ -153,21 +129,4 @@ public function getEmail(); */ public function getTimeZone(); - /** - * The timestamp when the account last accessed the site. - * - * A value of 0 means the user has never accessed the site. - * - * @return int - * Timestamp of the last access. - */ - public function getLastAccessedTime(); - - /** - * Returns the session hostname. - * - * @return string - */ - public function getHostname(); - } diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index f9d0d35..3495c56 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -98,13 +98,6 @@ public function getRoles($exclude_locked_roles = FALSE) { /** * {@inheritdoc} */ - public function getHostname() { - return $this->getAccount()->getHostname(); - } - - /** - * {@inheritdoc} - */ public function hasPermission($permission) { return $this->getAccount()->hasPermission($permission); } @@ -112,27 +105,6 @@ public function hasPermission($permission) { /** * {@inheritdoc} */ - public function getSessionId() { - return $this->getAccount()->getSessionId(); - } - - /** - * {@inheritdoc} - */ - public function getSecureSessionId() { - return $this->getAccount()->getSecureSessionId(); - } - - /** - * {@inheritdoc} - */ - public function getSessionData() { - return $this->getAccount()->getSessionData(); - } - - /** - * {@inheritdoc} - */ public function isAuthenticated() { return $this->getAccount()->isAuthenticated(); } @@ -179,12 +151,5 @@ public function getTimeZone() { return $this->getAccount()->getTimeZone(); } - /** - * {@inheritdoc} - */ - public function getLastAccessedTime() { - return $this->getAccount()->getLastAccessedTime(); - } - } diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index 62b4074..3496ac7 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Site\Settings; use Drupal\Core\Utility\Error; +use Drupal\user\UserInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; @@ -80,38 +81,30 @@ public function read($sid) { // cookies (eg. web crawlers). $cookies = $this->requestStack->getCurrentRequest()->cookies; if (empty($sid) || !$cookies->has($this->getName())) { - $user = new UserSession(); + $user = new AnonymousUserSession(); return ''; } - $values = $this->connection->query("SELECT u.*, s.* FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.default_langcode = 1 AND s.sid = :sid", array( + $values = $this->connection->query("SELECT s.* FROM {sessions} s WHERE s.sid = :sid", array( ':sid' => Crypt::hashBase64($sid), ))->fetchAssoc(); // We found the client's session record and they are an authenticated, // active user. - if ($values && $values['uid'] > 0 && $values['status'] == 1) { - // Add roles element to $user. - $rids = $this->connection->query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array( - ':uid' => $values['uid'], - ))->fetchCol(); - $values['roles'] = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids); - $user = new UserSession($values); + $user = NULL; + if ($values && $values['uid'] > 0) { + $user = \Drupal::entityManager()->getStorage('user')->load($values['uid']); + if ($user->isBlocked()) { + $user = NULL; + } } - elseif ($values) { - // The user is anonymous or blocked. Only preserve two fields from the - // {sessions} table. - $user = new UserSession(array( - 'session' => $values['session'], - 'access' => $values['access'], - )); - } - else { - // The session has expired. - $user = new UserSession(); + + if (!$user) { + // The user is anonymous, blocked or the session has expired. + $user = new AnonymousUserSession(); } - return $user->session; + return isset($values['session']) ? $values['session'] : ''; } /** @@ -141,7 +134,7 @@ public function write($sid, $value) { ->execute(); // Likewise, do not update access time more than once per 180 seconds. - if ($user->isAuthenticated() && REQUEST_TIME - $user->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { + if ($user instanceof UserInterface && REQUEST_TIME - $user->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { /** @var \Drupal\user\UserStorageInterface $storage */ $storage = \Drupal::entityManager()->getStorage('user'); $storage->updateLastAccessTimestamp($user, REQUEST_TIME); diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index feb935c..c3f4e24 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -31,34 +31,6 @@ class UserSession implements AccountInterface { protected $roles = array('anonymous'); /** - * Session ID. - * - * @var string. - */ - public $sid; - - /** - * Secure session ID. - * - * @var string. - */ - public $ssid; - - /** - * Session data. - * - * @var array. - */ - public $session; - - /** - * The Unix timestamp when this session last requested a page. - * - * @var string. - */ - protected $timestamp; - - /** * The name of this account. * * @var string @@ -94,13 +66,6 @@ class UserSession implements AccountInterface { protected $timezone; /** - * The hostname for this user session. - * - * @var string - */ - protected $hostname = ''; - - /** * Constructs a new user session. * * @param array $values @@ -147,27 +112,6 @@ public function hasPermission($permission) { /** * {@inheritdoc} */ - public function getSecureSessionId() { - return $this->ssid; - } - - /** - * {@inheritdoc} - */ - public function getSessionData() { - return $this->session; - } - - /** - * {@inheritdoc} - */ - public function getSessionId() { - return $this->sid; - } - - /** - * {@inheritdoc} - */ public function isAuthenticated() { return $this->uid > 0; } @@ -229,20 +173,6 @@ public function getTimeZone() { } /** - * {@inheritdoc} - */ - public function getLastAccessedTime() { - return $this->timestamp; - } - - /** - * {@inheritdoc} - */ - public function getHostname() { - return $this->hostname; - } - - /** * Returns the role storage object. * * @return \Drupal\user\RoleStorageInterface diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index c003db2..c364d46 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\user\UserInterface; /** @@ -184,37 +185,6 @@ public function getRoles($exclude_locked_roles = FALSE) { /** * {@inheritdoc} */ - public function getSecureSessionId() { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function getSessionData() { - return array(); - } - /** - * {@inheritdoc} - */ - public function getSessionId() { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function getHostname() { - if (!isset($this->hostname) && \Drupal::hasRequest()) { - $this->hostname = \Drupal::request()->getClientIp(); - } - - return $this->hostname; - } - - /** - * {@inheritdoc} - */ public function hasRole($rid) { return in_array($rid, $this->getRoles()); } @@ -442,34 +412,34 @@ public function getChangedTime() { */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = BaseFieldDefinition::create('integer') - ->setLabel(t('User ID')) - ->setDescription(t('The user ID.')) + ->setLabel(new TranslationWrapper('User ID')) + ->setDescription(new TranslationWrapper('The user ID.')) ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The user UUID.')) + ->setLabel(new TranslationWrapper('UUID')) + ->setDescription(new TranslationWrapper('The user UUID.')) ->setReadOnly(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The user language code.')); + ->setLabel(new TranslationWrapper('Language code')) + ->setDescription(new TranslationWrapper('The user language code.')); $fields['preferred_langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Preferred language code')) - ->setDescription(t("The user's preferred language code for receiving emails and viewing the site.")); + ->setLabel(new TranslationWrapper('Preferred language code')) + ->setDescription(new TranslationWrapper("The user's preferred language code for receiving emails and viewing the site.")); $fields['preferred_admin_langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Preferred admin language code')) - ->setDescription(t("The user's preferred language code for viewing administration pages.")) + ->setLabel(new TranslationWrapper('Preferred admin language code')) + ->setDescription(new TranslationWrapper("The user's preferred language code for viewing administration pages.")) ->setDefaultValue(''); // The name should not vary per language. The username is the visual // identifier for a user and needs to be consistent in all languages. $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of this user.')) + ->setLabel(new TranslationWrapper('Name')) + ->setDescription(new TranslationWrapper('The name of this user.')) ->setDefaultValue('') ->setConstraints(array( // No Length constraint here because the UserName constraint also covers @@ -479,62 +449,62 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $fields['pass'] = BaseFieldDefinition::create('string') - ->setLabel(t('Password')) - ->setDescription(t('The password of this user (hashed).')); + ->setLabel(new TranslationWrapper('Password')) + ->setDescription(new TranslationWrapper('The password of this user (hashed).')); $fields['mail'] = BaseFieldDefinition::create('email') - ->setLabel(t('Email')) - ->setDescription(t('The email of this user.')) + ->setLabel(new TranslationWrapper('Email')) + ->setDescription(new TranslationWrapper('The email of this user.')) ->setDefaultValue('') ->setConstraints(array('UserMailUnique' => array())); // @todo Convert to a text field in https://drupal.org/node/1548204. $fields['signature'] = BaseFieldDefinition::create('string') - ->setLabel(t('Signature')) - ->setDescription(t('The signature of this user.')) + ->setLabel(new TranslationWrapper('Signature')) + ->setDescription(new TranslationWrapper('The signature of this user.')) ->setTranslatable(TRUE); $fields['signature_format'] = BaseFieldDefinition::create('string') - ->setLabel(t('Signature format')) - ->setDescription(t('The signature format of this user.')); + ->setLabel(new TranslationWrapper('Signature format')) + ->setDescription(new TranslationWrapper('The signature format of this user.')); $fields['timezone'] = BaseFieldDefinition::create('string') - ->setLabel(t('Timezone')) - ->setDescription(t('The timezone of this user.')) + ->setLabel(new TranslationWrapper('Timezone')) + ->setDescription(new TranslationWrapper('The timezone of this user.')) ->setSetting('max_length', 32); $fields['status'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('User status')) - ->setDescription(t('Whether the user is active or blocked.')) + ->setLabel(new TranslationWrapper('User status')) + ->setDescription(new TranslationWrapper('Whether the user is active or blocked.')) ->setDefaultValue(FALSE); $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the user was created.')); + ->setLabel(new TranslationWrapper('Created')) + ->setDescription(new TranslationWrapper('The time that the user was created.')); $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the user was last edited.')); + ->setLabel(new TranslationWrapper('Changed')) + ->setDescription(new TranslationWrapper('The time that the user was last edited.')); $fields['access'] = BaseFieldDefinition::create('timestamp') - ->setLabel(t('Last access')) - ->setDescription(t('The time that the user last accessed the site.')) + ->setLabel(new TranslationWrapper('Last access')) + ->setDescription(new TranslationWrapper('The time that the user last accessed the site.')) ->setDefaultValue(0); $fields['login'] = BaseFieldDefinition::create('timestamp') - ->setLabel(t('Last login')) - ->setDescription(t('The time that the user last logged in.')) + ->setLabel(new TranslationWrapper('Last login')) + ->setDescription(new TranslationWrapper('The time that the user last logged in.')) ->setDefaultValue(0); $fields['init'] = BaseFieldDefinition::create('email') - ->setLabel(t('Initial email')) - ->setDescription(t('The email address used for initial account creation.')) + ->setLabel(new TranslationWrapper('Initial email')) + ->setDescription(new TranslationWrapper('The email address used for initial account creation.')) ->setDefaultValue(''); $fields['roles'] = BaseFieldDefinition::create('entity_reference') ->setCustomStorage(TRUE) - ->setLabel(t('Roles')) + ->setLabel(new TranslationWrapper('Roles')) ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) - ->setDescription(t('The roles the user has.')) + ->setDescription(new TranslationWrapper('The roles the user has.')) ->setSetting('target_type', 'user_role'); return $fields; diff --git a/core/modules/user/src/UserInterface.php b/core/modules/user/src/UserInterface.php index e2c44d0..fc8105a 100644 --- a/core/modules/user/src/UserInterface.php +++ b/core/modules/user/src/UserInterface.php @@ -182,4 +182,14 @@ public function block(); */ public function getInitialEmail(); + /** + * The timestamp when the account last accessed the site. + * + * A value of 0 means the user has never accessed the site. + * + * @return int + * Timestamp of the last access. + */ + public function getLastAccessedTime(); + } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 933b7ed..1da916b 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -804,11 +804,13 @@ public function testClearCachedBundles() { public function testGetBundleInfo($entity_type_id, $expected) { $apple = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $apple->expects($this->once()) - ->method('getLabel') + ->method('get') + ->with('label') ->will($this->returnValue('Apple')); $banana = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $banana->expects($this->once()) - ->method('getLabel') + ->method('get') + ->with('label') ->will($this->returnValue('Banana')); $this->setUpEntityManager(array( 'apple' => $apple, @@ -849,11 +851,13 @@ public function providerTestGetBundleInfo() { public function testGetAllBundleInfo() { $apple = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $apple->expects($this->once()) - ->method('getLabel') + ->method('get') + ->with('label') ->will($this->returnValue('Apple')); $banana = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $banana->expects($this->once()) - ->method('getLabel') + ->method('get') + ->with('label') ->will($this->returnValue('Banana')); $this->setUpEntityManager(array( 'apple' => $apple, diff --git a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php index 59f6f1c..7c2a1cc 100644 --- a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php @@ -9,10 +9,6 @@ use Drupal\Tests\UnitTestCase; use Drupal\Core\Session\AnonymousUserSession; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Scope; -use Symfony\Component\HttpFoundation\RequestStack; /** * @coversDefaultClass \Drupal\Core\Session\AnonymousUserSession @@ -21,42 +17,6 @@ class AnonymousUserSessionTest extends UnitTestCase { /** - * Tests creating an AnonymousUserSession when the request is available. - * - * @covers ::__construct - */ - public function testAnonymousUserSessionWithRequest() { - $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); - $request->expects($this->once()) - ->method('getClientIp') - ->will($this->returnValue('test')); - $container = new ContainerBuilder(); - $requestStack = new RequestStack(); - $requestStack->push($request); - $container->set('request_stack', $requestStack); - \Drupal::setContainer($container); - - $anonymous_user = new AnonymousUserSession(); - - $this->assertSame('test', $anonymous_user->getHostname()); - } - - /** - * Tests creating an AnonymousUserSession when the request is not available. - * - * @covers ::__construct - */ - public function testAnonymousUserSessionWithNoRequest() { - $container = new ContainerBuilder(); - - \Drupal::setContainer($container); - - $anonymous_user = new AnonymousUserSession(); - - $this->assertSame('', $anonymous_user->getHostname()); - } - - /** * Tests the method getRoles exclude or include locked roles based in param. * * @covers ::getRoles