diff -u b/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php --- b/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -188,11 +188,11 @@ } /** - * Returns the typed data service. + * Returns the typed data manager. * * @return \Drupal\Core\TypedData\TypedDataManager */ - protected function getTypedData() { + protected function getTypedDataManager() { return \Drupal::typedData(); } @@ -287,7 +287,7 @@ * {@inheritdoc} */ public function validate() { - return $this->getTypedData()->getValidator()->validate($this); + return $this->getTypedDataManager()->getValidator()->validate($this); } /** @@ -438,7 +438,7 @@ if (isset($this->values[$property_name][$langcode])) { $value = $this->values[$property_name][$langcode]; } - $field = $this->getTypedData()->getPropertyInstance($this, $property_name, $value); + $field = $this->getTypedDataManager()->getPropertyInstance($this, $property_name, $value); $field->setLangcode($langcode); $this->fields[$property_name][$langcode] = $field; } @@ -543,7 +543,7 @@ /** * {@inheritdoc} */ - public function access($operation = 'view', AccountInterface $account = NULL) { + public function access($operation, AccountInterface $account = NULL) { if ($operation == 'create') { return $this->getEntityManager() ->getAccessController($this->entityType) diff -u b/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php --- b/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -262,7 +262,7 @@ /** * {@inheritdoc} */ - public function access($operation = 'view', AccountInterface $account = NULL) { + public function access($operation, AccountInterface $account = NULL) { if ($operation == 'create') { return $this->getEntityManager() ->getAccessController($this->entityType) diff -u b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php --- b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Tests\UnitTestCase; +use MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass; /** * Tests \Drupal\Core\Entity\ContentEntityBase; @@ -15,6 +16,13 @@ class ContentEntityBaseUnitTest extends UnitTestCase { /** + * The bundle of the entity under test. + * + * @var string + */ + protected $bundle; + + /** * The entity under test. * * @var \Drupal\Core\Entity\ContentEntityBase @@ -29,11 +37,18 @@ protected $entityManager; /** + * The type of the entity under test. + * + * @var string + */ + protected $entityType; + + /** * The typed data manager used for testing. * * @var \Drupal\Core\TypedData\TypedDataManager */ - protected $typedData; + protected $typedDataManager; /** * The UUID generator used for testing. @@ -59,45 +74,522 @@ public function setUp() { $values = array(); - $entity_type = $this->randomName(); - $bundle = $this->randomName(); - $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase') + $this->entityType = $this->randomName(); + $this->bundle = $this->randomName(); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager') ->disableOriginalConstructor() - ->setMethods(array('baseFieldDefinitions', 'languageList')) + ->getMock(); + + $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase') + ->setConstructorArgs(array($values, $this->entityType, $this->bundle)) + ->setMethods(array('baseFieldDefinitions', 'checkPlain', 'formatString', 'getEntityManager', 'getTypedDataManager', 'getUuid', 'languageList', 'languageLoad')) ->getMock(); $this->entity->expects($this->any()) ->method('baseFieldDefinitions') ->will($this->returnValue(array())); - $this->entity->expects($this->once()) + $this->entity->expects($this->any()) + ->method('getEntityManager') + ->will($this->returnValue($this->entityManager)); + $this->entity->expects($this->any()) + ->method('getUuid') + ->will($this->returnValue($this->uuid)); + $this->entity->expects($this->any()) + ->method('getTypedDataManager') + ->will($this->returnValue($this->typedDataManager)); + $this->entity->expects($this->any()) ->method('languageList') ->will($this->returnValue(array())); - $this->entity->expects($this->once()) + $this->entity->expects($this->any()) + ->method('languageLoad') + ->will($this->returnValue(NULL)); + $this->entity->expects($this->any()) ->method('checkPlain') ->will($this->returnArgument(0)); - $this->entity->expects($this->once()) + $this->entity->expects($this->any()) ->method('formatString') ->will($this->returnArgument(0)); - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); - $this->entity->expects($this->once()) - ->method('getEntityManager') - ->will($this->returnValue($this->entityManager)); - $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); - $this->entity->expects($this->once()) - ->method('getUuid') - ->will($this->returnValue($this->uuid)); - $this->typedData = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager') - ->disableOriginalConstructor() - ->getMock(); - $this->entity->expects($this->once()) - ->method('getTypedData') - ->will($this->returnValue($this->typedData)); - $this->entity->__construct($values, $entity_type, $bundle); } /** - * Tests defaultConfiguration(). + * Tests setNewRevision(). + */ + public function testSetNewRevision() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests isNewRevision(). + */ + public function testIsNewRevision() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests isDefaultRevision(). + */ + public function testIsDefaultRevision() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getRevisionId(). + */ + public function testGetRevisionId() { + $this->assertNull($this->entity->getRevisionId()); + } + + /** + * Tests isTranslatable(). + */ + public function testIsTranslatable() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests preSaveRevision(). + */ + public function testPreSaveRevision() { + // This method is internal, so check for errors on calling it only. + $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface'); + $record = new \stdClass(); + $this->entity->preSaveRevision($storage, $record); + } + + /** + * Tests getDefinition(). + */ + public function testGetDefinition() { + $definition = $this->entity->getDefinition(); + $this->assertInternalType('array', $definition); + $this->arrayHasKey('type', $definition); + $this->assertInternalType('string', $definition['type']); + } + + /** + * Tests getValue(). + */ + public function testGetValue() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests setValue(). + */ + public function testSetValue() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getString(). + */ + public function testGetString() { + $this->assertInternalType('string', $this->entity->getString()); + } + + /** + * Tests validate(). + */ + public function testValidate() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests applyDefaultValue(). + */ + public function testApplyDefaultValue() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getConstraints(). + */ + public function testGetConstraints() { + $this->assertInternalType('array', $this->entity->getConstraints()); + } + + /** + * Tests getName(). + */ + public function testGetName() { + $this->assertNull($this->entity->getConstraints()); + } + + /** + * Tests getRoot(). + */ + public function testGetRoot() { + $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->getRoot())); + } + + /** + * Tests getPropertyPath(). + */ + public function testGetPropertyPath() { + $this->assertSame('', $this->entity->getPropertyPath()); + } + + /** + * Tests getParent(). + */ + public function testGetParent() { + $this->assertNull($this->entity->getParent()); + } + + /** + * Tests setContext(). + */ + public function testSetContext() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests clearTranslationCache(). + */ + public function testClearTranslationCache() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests id(). + */ + public function testId() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests bundle(). + */ + public function testBundle() { + $this->assertSame($this->bundle, $this->entity->bundle()); + } + + /** + * Tests uuid(). + */ + public function testUuid() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests hasField(). + */ + public function testHasField() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests get(). + */ + public function testGet() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getTranslatedField(). + */ + public function testGetTranslatedField() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests set(). + */ + public function testSet() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getProperties(). + */ + public function testGetProperties() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getIterator(). + */ + public function testGetIterator() { + $this->assertInstanceOf('\Traversable', $this->entity->getIterator()); + } + + /** + * Tests getPropertyDefinition(). + */ + public function testGetPropertyDefinition() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getPropertyDefinitions(). + */ + public function testGetPropertyDefinitions() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getPropertyValues(). + */ + public function testGetPropertyValues() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests setPropertyValues(). + */ + public function testSetPropertyValues() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests isEmpty(). + */ + public function testIsEmpty() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests access(). + */ + public function testAccess() { + $access = $this->getMock('\Drupal\Core\Entity\EntityAccessControllerInterface'); + $operation = $this->randomName(); + $access->expects($this->at(0)) + ->method('access') + ->with($this->entity, $operation) + ->will($this->returnValue(TRUE)); + $access->expects($this->at(1)) + ->method('createAccess') + ->will($this->returnValue(TRUE)); + $this->entityManager->expects($this->exactly(2)) + ->method('getAccessController') + ->will($this->returnValue($access)); + $this->assertTrue($this->entity->access($operation)); + $this->assertTrue($this->entity->access('create')); + } + + /** + * Tests language(). + */ + public function testLanguage() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getDefaultLanguage(). + */ + public function testGetDefaultLanguage() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests onChange(). + */ + public function testOnChange() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getTranslation(). + */ + public function testGetTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getUntranslated(). + */ + public function testGetUntranslated() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests initializeTranslation(). + */ + public function testInitializeTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests hasTranslation(). + */ + public function testHasTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests addTranslation(). + */ + public function testAddTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests removeTranslation(). + */ + public function testRemoveTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests initTranslation(). + */ + public function testInitTranslation() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests getTranslationLanguages(). + */ + public function testGetTranslationLanguages() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests translations(). + */ + public function testTranslations() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests updateOriginalValues(). + */ + public function testUpdateOriginalValues() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests __get(). + */ + public function test__get() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests __set(). + */ + public function test__set() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests __isset(). + */ + public function test__isset() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests __unset(). + */ + public function test__unset() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests createDuplicate(). + */ + public function testCreateDuplicate() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests __clone(). + */ + public function test__clone() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests label(). + */ + public function testLabel() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests referencedEntities(). + */ + public function testReferencedEntities() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests enforceIsNew(). + */ + public function testEnforceIsNew() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests entityType(). + */ + public function testEntityType() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests entityInfo(). + */ + public function testEntityInfo() { + // @todo Finish this test method. + $this->fail(); + } + + /** + * Tests preSave(). */ - public function testDefaultConfiguration() { -// $this->fail(); -// $this->assertInternalType('array', $this->paymentMethodPlugin->defaultConfiguration()); + public function testPreSave() { + // @todo Finish this test method. + $this->fail(); } } diff -u b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php --- b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -59,8 +59,11 @@ public function setUp() { $values = array(); $this->entityType = $this->randomName(); + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\Entity') ->setConstructorArgs(array($values, $this->entityType)) ->setMethods(array('getEntityManager', 'getUuid', 'languageLoad'))