diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index ba016cb..e057560 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -141,7 +141,7 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) { $this->entityTypeId = $entity_type; $this->bundle = $bundle ? $bundle : $this->entityTypeId; - $this->languages = $this->languageList(Language::STATE_ALL); + $this->languages = $this->languageManager()->getLanguages(Language::STATE_ALL); foreach ($values as $key => $value) { // If the key matches an existing property set the value to the property @@ -169,20 +169,13 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans } /** - * Wraps $this->languageList(). - */ - protected function languageList($flags = Language::STATE_CONFIGURABLE) { - return language_list($flags); - } - - /** * Returns the typed data manager. * * @return \Drupal\Core\TypedData\TypedDataManager */ protected function typedDataManager() { if (!$this->typedDataManager) { - $this->typedDataManager = \Drupal::typedDataManager(); + return \Drupal::typedDataManager(); } return $this->typedDataManager; diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index b3b3546..913a316 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -59,6 +59,13 @@ protected $urlGenerator; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** * Constructs an Entity object. * * @param array $values @@ -76,26 +83,32 @@ public function __construct(array $values, $entity_type) { } /** - * Wraps language_load(). - */ - protected function languageLoad($langcode) { - return language_load($langcode); - } - - /** * Returns the entity manager. * * @return \Drupal\Core\Entity\EntityManagerInterface */ protected function entityManager() { if (!$this->entityManager) { - $this->entityManager = \Drupal::entityManager(); + return \Drupal::entityManager(); } return $this->entityManager; } /** + * Returns the language manager. + * + * @return \Drupal\Core\Language\LanguageManagerInterface + */ + protected function languageManager() { + if (!$this->languageManager) { + return \Drupal::languageManager(); + } + + return $this->languageManager; + } + + /** * Returns the UUID generator. * * @return \Drupal\Component\Uuid\UuidInterface @@ -310,7 +323,7 @@ public function access($operation, AccountInterface $account = NULL) { * {@inheritdoc} */ public function language() { - $language = $this->languageLoad($this->langcode); + $language = $this->languageManager()->getLanguage($this->langcode); if (!$language) { // Make sure we return a proper language object. $language = new Language(array('id' => Language::LANGCODE_NOT_SPECIFIED)); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index d7271d9..771af60 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -25,11 +25,11 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { protected $entity; /** - * The entity info used for testing.. + * The entity type used for testing. * * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $entityInfo; + protected $entityType; /** * The entity manager used for testing. @@ -39,11 +39,11 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { protected $entityManager; /** - * The type of the entity under test. + * The type ID of the entity under test. * * @var string */ - protected $entityType; + protected $entityTypeId; /** * The UUID generator used for testing. @@ -53,6 +53,13 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { protected $uuid; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $languageManager; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -68,30 +75,30 @@ public static function getInfo() { */ public function setUp() { $values = array(); - $this->entityType = $this->randomName(); + $this->entityTypeId = $this->randomName(); - $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); $this->entityManager->expects($this->any()) ->method('getDefinition') - ->with($this->entityType) - ->will($this->returnValue($this->entityInfo)); + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + $this->languageManager = $this->getMock('\Drupal\Core\Language\LanguageManagerInterface'); + $this->languageManager->expects($this->any()) + ->method('getLanguage') + ->will($this->returnValue(NULL)); + $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); + $container->set('language_manager', $this->languageManager); \Drupal::setContainer($container); - $this->entity = $this->getMockBuilder('\Drupal\Core\Config\Entity\ConfigEntityBase') - ->setConstructorArgs(array($values, $this->entityType)) - ->setMethods(array('languageLoad')) - ->getMock(); - $this->entity->expects($this->any()) - ->method('languageLoad') - ->will($this->returnValue(NULL)); + $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', array($values, $this->entityTypeId)); } /** @@ -175,7 +182,7 @@ public function testIsSyncing() { * @covers ::createDuplicate */ public function testCreateDuplicate() { - $this->entityInfo->expects($this->once()) + $this->entityType->expects($this->once()) ->method('getKey') ->with('id') ->will($this->returnValue('id')); @@ -196,7 +203,7 @@ public function testCreateDuplicate() { public function testSort() { $this->entityManager->expects($this->any()) ->method('getDefinition') - ->with($this->entityType) + ->with($this->entityTypeId) ->will($this->returnValue(array( 'entity_keys' => array( 'label' => 'label', diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index 789306b..2aab55a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -32,11 +32,11 @@ class ContentEntityBaseUnitTest extends UnitTestCase { protected $entity; /** - * The entity info used for testing.. + * The entity type used for testing. * * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $entityInfo; + protected $entityType; /** * The entity manager used for testing. @@ -46,11 +46,11 @@ class ContentEntityBaseUnitTest extends UnitTestCase { protected $entityManager; /** - * The type of the entity under test. + * The type ID of the entity under test. * * @var string */ - protected $entityType; + protected $entityTypeId; /** * The typed data manager used for testing. @@ -60,6 +60,13 @@ class ContentEntityBaseUnitTest extends UnitTestCase { protected $typedDataManager; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $languageManager; + + /** * The UUID generator used for testing. * * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject @@ -82,19 +89,19 @@ public static function getInfo() { */ public function setUp() { $values = array(); - $this->entityType = $this->randomName(); + $this->entityTypeId = $this->randomName(); $this->bundle = $this->randomName(); - $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); $this->entityManager->expects($this->any()) ->method('getDefinition') - ->with($this->entityType) - ->will($this->returnValue($this->entityInfo)); + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); $this->entityManager->expects($this->any()) ->method('getFieldDefinitions') - ->with($this->entityType, $this->bundle) + ->with($this->entityTypeId, $this->bundle) ->will($this->returnValue(array( 'id' => array( 'type' => 'integer_field', @@ -107,22 +114,22 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); + $this->languageManager = $this->getMock('\Drupal\Core\Language\LanguageManagerInterface'); + $this->languageManager->expects($this->any()) + ->method('getLanguages') + ->will($this->returnValue(array())); + $this->languageManager->expects($this->any()) + ->method('getLanguage') + ->will($this->returnValue(NULL)); + $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); $container->set('typed_data_manager', $this->typedDataManager); + $container->set('language_manager', $this->languageManager); \Drupal::setContainer($container); - $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase') - ->setConstructorArgs(array($values, $this->entityType, $this->bundle)) - ->setMethods(array('languageList', 'languageLoad')) - ->getMockForAbstractClass(); - $this->entity->expects($this->any()) - ->method('languageList') - ->will($this->returnValue(array())); - $this->entity->expects($this->any()) - ->method('languageLoad') - ->will($this->returnValue(NULL)); + $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle)); } /** @@ -130,11 +137,11 @@ public function setUp() { * @covers ::setNewRevision */ public function testIsNewRevision() { - $this->entityInfo->expects($this->at(0)) + $this->entityType->expects($this->at(0)) ->method('hasKey') ->with('revision') ->will($this->returnValue(FALSE)); - $this->entityInfo->expects($this->at(1)) + $this->entityType->expects($this->at(1)) ->method('hasKey') ->with('revision') ->will($this->returnValue(TRUE)); @@ -170,7 +177,7 @@ public function testGetRevisionId() { public function testIsTranslatable() { $this->entityManager->expects($this->at(0)) ->method('getBundleInfo') - ->with($this->entityType) + ->with($this->entityTypeId) ->will($this->returnValue(array( $this->bundle => array( 'translatable' => TRUE, @@ -317,7 +324,7 @@ public function testLabel() { $callback_container->expects($this->once()) ->method(__FUNCTION__) ->will($this->returnValue($callback_label)); - $this->entityInfo->expects($this->once()) + $this->entityType->expects($this->once()) ->method('getLabelCallback') ->will($this->returnValue(array($callback_container, __FUNCTION__))); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index a467a90..df10310 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -25,11 +25,11 @@ class EntityUnitTest extends UnitTestCase { protected $entity; /** - * The entity info used for testing.. + * The entity type used for testing. * * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $entityInfo; + protected $entityType; /** * The entity manager used for testing. @@ -60,6 +60,13 @@ class EntityUnitTest extends UnitTestCase { protected $uuid; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $languageManager; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -77,28 +84,29 @@ public function setUp() { $values = array(); $this->entityTypeId = $this->randomName(); - $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); $this->entityManager->expects($this->any()) ->method('getDefinition') ->with($this->entityTypeId) - ->will($this->returnValue($this->entityInfo)); + ->will($this->returnValue($this->entityType)); $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + $this->languageManager = $this->getMock('\Drupal\Core\Language\LanguageManagerInterface'); + $this->languageManager->expects($this->any()) + ->method('getLanguage') + ->will($this->returnValue(NULL)); + $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); + $container->set('language_manager', $this->languageManager); + \Drupal::setContainer($container); - $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\Entity') - ->setConstructorArgs(array($values, $this->entityTypeId)) - ->setMethods(array('languageLoad')) - ->getMock(); - $this->entity->expects($this->any()) - ->method('languageLoad') - ->will($this->returnValue(NULL)); + $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\Entity', array($values, $this->entityTypeId)); } /** @@ -159,13 +167,13 @@ public function testLabel() { $callback_container->expects($this->once()) ->method(__FUNCTION__) ->will($this->returnValue($callback_label)); - $this->entityInfo->expects($this->at(0)) + $this->entityType->expects($this->at(0)) ->method('getLabelCallback') ->will($this->returnValue(array($callback_container, __FUNCTION__))); - $this->entityInfo->expects($this->at(1)) + $this->entityType->expects($this->at(1)) ->method('getLabelCallback') ->will($this->returnValue(NULL)); - $this->entityInfo->expects($this->at(2)) + $this->entityType->expects($this->at(2)) ->method('getKey') ->with('label') ->will($this->returnValue('label'));