diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 4af470e..f90036b 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; @@ -186,6 +187,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 5ba64f2..722b4e1 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -734,7 +734,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/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index dba7a94..95db7d9 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -412,6 +412,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. @@ -421,9 +424,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 1baf7bd..9bfc30b 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')) ->setRequired(TRUE); 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 9ab60a4..a7a11d2 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; @@ -42,13 +44,15 @@ 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')) ->setRequired(TRUE); $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 2aa8fa5..6583d12 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -99,13 +99,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); } @@ -113,27 +106,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(); } @@ -180,12 +152,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 42daba5..cef6688 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; @@ -71,38 +72,30 @@ public function read($sid) { // cookies (eg. web crawlers). $cookies = $this->requestStack->getCurrentRequest()->cookies; if (empty($sid) || !$cookies->has($this->getName())) { - $_session_user = new UserSession(); + $_session_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.roles_target_id as rid FROM {user__roles} ur WHERE ur.entity_id = :uid", array( - ':uid' => $values['uid'], - ))->fetchCol(); - $values['roles'] = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids); - $_session_user = new UserSession($values); + $_session_user = NULL; + if ($values && $values['uid'] > 0) { + $_session_user = \Drupal::entityManager()->getStorage('user')->load($values['uid']); + if ($_session_user->isBlocked()) { + $_session_user = NULL; + } } - elseif ($values) { - // The user is anonymous or blocked. Only preserve two fields from the - // {sessions} table. - $_session_user = new UserSession(array( - 'session' => $values['session'], - 'access' => $values['access'], - )); - } - else { - // The session has expired. - $_session_user = new UserSession(); + + if (!$_session_user) { + // The user is anonymous, blocked or the session has expired. + $_session_user = new AnonymousUserSession(); } - return $_session_user->session; + return isset($values['session']) ? $values['session'] : ''; } /** @@ -126,7 +119,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 6af360d..2964b79 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 76122bc..aa43830 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Language\LanguageInterface; +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()); } @@ -463,23 +433,23 @@ 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.")) // @todo: Define this via an options provider once // https://www.drupal.org/node/2329937 is completed. ->addPropertyConstraints('value', array( @@ -487,8 +457,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $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.")) // @todo: A default value of NULL is ignored, so we have to specify // an empty field item structure instead. Fix this in // https://www.drupal.org/node/2318605. @@ -502,8 +472,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { // 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 @@ -513,24 +483,24 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $fields['pass'] = BaseFieldDefinition::create('password') - ->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('') ->addConstraint('UserMailUnique') ->addConstraint('UserMailRequired'); // @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.')) // @todo: Define this via an options provider once // https://www.drupal.org/node/2329937 is completed. ->addPropertyConstraints('value', array( @@ -538,8 +508,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $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) // @todo: Define this via an options provider once // https://www.drupal.org/node/2329937 is completed. @@ -548,37 +518,37 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $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') - ->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 c6f3b2a..97b4687 100644 --- a/core/modules/user/src/UserInterface.php +++ b/core/modules/user/src/UserInterface.php @@ -202,4 +202,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 8c159ec..984b8db 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -814,11 +814,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, @@ -859,11 +861,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