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,7 +8,6 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Tests\UnitTestCase; -use MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass; /** * Tests \Drupal\Core\Entity\ContentEntityBase; @@ -90,7 +89,11 @@ ->getMock(); $this->entity->expects($this->any()) ->method('baseFieldDefinitions') - ->will($this->returnValue(array())); + ->will($this->returnValue(array( + 'id' => array( + 'type' => 'integer_field', + ), + ))); $this->entity->expects($this->any()) ->method('getEntityManager') ->will($this->returnValue($this->entityManager)); @@ -115,27 +118,39 @@ } /** - * Tests setNewRevision(). - */ - public function testSetNewRevision() { - // @todo Finish this test method. - $this->fail(); - } - - /** - * Tests isNewRevision(). + * Tests isNewRevision() and setNewRevision(). */ public function testIsNewRevision() { - // @todo Finish this test method. - $this->fail(); + $this->entityManager->expects($this->at(3)) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue(array( + 'entity_keys' => array( + 'revision' => $this->randomName(), + ), + ))); + // The value defaults to FALSE. + $this->assertFalse($this->entity->isNewRevision()); + // Set the value explicitly and test it is returned. + $this->entity->setNewRevision(TRUE); + $this->assertTrue($this->entity->isNewRevision()); + // Reset the value and test it is returned. + $this->entity->setNewRevision(FALSE); + $this->assertFalse($this->entity->isNewRevision()); + // Because isNewRevision() can now find an entity key, it returns TRUE. + $this->assertTrue($this->entity->isNewRevision()); } /** * Tests isDefaultRevision(). */ public function testIsDefaultRevision() { - // @todo Finish this test method. - $this->fail(); + // The default value is TRUE. + $this->assertTrue($this->entity->isDefaultRevision()); + // We override the value, but it does not affect this call. + $this->assertTrue($this->entity->isDefaultRevision(FALSE)); + // The last call changed the return value for this call. + $this->assertFalse($this->entity->isDefaultRevision()); } /** @@ -149,8 +164,16 @@ * Tests isTranslatable(). */ public function testIsTranslatable() { - // @todo Finish this test method. - $this->fail(); + $this->entityManager->expects($this->at(0)) + ->method('getBundleInfo') + ->with($this->entityType) + ->will($this->returnValue(array( + $this->bundle => array( + 'translatable' => TRUE, + ), + ))); + $this->assertTrue($this->entity->isTranslatable()); + $this->assertFalse($this->entity->isTranslatable()); } /** @@ -200,8 +223,26 @@ * Tests validate(). */ public function testValidate() { - // @todo Finish this test method. - $this->fail(); + $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); + $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList') + ->setMethods(NULL) + ->getMock(); + $non_empty_violation_list = clone $empty_violation_list; + $violation = $this->getMock('\Symfony\Component\Validator\ConstraintViolationInterface'); + $non_empty_violation_list->add($violation); + $validator->expects($this->at(0)) + ->method('validate') + ->with($this->entity) + ->will($this->returnValue($empty_violation_list)); + $validator->expects($this->at(1)) + ->method('validate') + ->with($this->entity) + ->will($this->returnValue($non_empty_violation_list)); + $this->typedDataManager->expects($this->exactly(2)) + ->method('getValidator') + ->will($this->returnValue($validator)); + $this->assertSame(0, count($this->entity->validate())); + $this->assertSame(1, count($this->entity->validate())); } /** @@ -251,16 +292,9 @@ * Tests setContext(). */ public function testSetContext() { - // @todo Finish this test method. - $this->fail(); - } - - /** - * Tests clearTranslationCache(). - */ - public function testClearTranslationCache() { - // @todo Finish this test method. - $this->fail(); + $name = $this->randomName(); + $parent = $this->getMock('\Drupal\Core\TypedData\TypedDataInterface'); + $this->entity->setContext($name, $parent); } /** @@ -303,14 +337,6 @@ } /** - * Tests getTranslatedField(). - */ - public function testGetTranslatedField() { - // @todo Finish this test method. - $this->fail(); - } - - /** * Tests set(). */ public function testSet() { @@ -402,14 +428,6 @@ } /** - * Tests getDefaultLanguage(). - */ - public function testGetDefaultLanguage() { - // @todo Finish this test method. - $this->fail(); - } - - /** * Tests onChange(). */ public function testOnChange() { @@ -434,14 +452,6 @@ } /** - * Tests initializeTranslation(). - */ - public function testInitializeTranslation() { - // @todo Finish this test method. - $this->fail(); - } - - /** * Tests hasTranslation(). */ public function testHasTranslation() { @@ -498,59 +508,58 @@ } /** - * 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(); + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue(array( + 'entity_keys' => array( + 'id' => 'id', + 'revision' => 'revision', + 'uuid' => 'uuid', + ), + ))); + $duplicate = $this->entity->createDuplicate(); + $this->assertInstanceOf('\Drupal\Core\Entity\Entity', $duplicate); + $this->assertNotSame(spl_object_hash($this->entity), spl_object_hash($duplicate)); } /** * Tests label(). */ public function testLabel() { - // @todo Finish this test method. - $this->fail(); + // Make a mock with one method that we use as the entity's uri_callback. We + // check that it is called, and that the entity's label is the callback's + // return value. + $callback_label = $this->randomName(); + $property_label = $this->randomName(); + $callback_container = $this->getMock(get_class()); + $callback_container->expects($this->once()) + ->method(__FUNCTION__) + ->will($this->returnValue($callback_label)); + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue(array( + 'label_callback' => array($callback_container, __FUNCTION__), + ))); + + // Set a dummy property on the entity under test to test that the label can + // be returned form a property if there is no callback. + $this->entityManager->expects($this->at(1)) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue(array( + 'entity_keys' => array( + 'label' => 'label', + ), + ))); + $this->entity->label = $property_label; + + $this->assertSame($callback_label, $this->entity->label()); + $this->assertSame($property_label, $this->entity->label()); } /** @@ -562,34 +571,2 @@ } - - /** - * 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 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 @@ -192,7 +192,7 @@ ->with($this->entityType) ->will($this->returnValue(array( $this->entityType => array( - 'uri_callback' => array($callback_container, __FUNCTION__) + 'uri_callback' => array($callback_container, __FUNCTION__), ), ))); only in patch2: unchanged: --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -239,7 +239,7 @@ function _block_get_renderable_region($list = array()) { $settings = $block->get('settings'); if ($not_cacheable || in_array($settings['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { // Non-cached blocks get built immediately. - if ($block->access()) { + if ($block->access('view')) { $build[$key] = entity_view($block, 'block'); } } @@ -435,7 +435,7 @@ function block_load($entity_id) { function _block_get_renderable_block($element) { $block = $element['#block']; // Don't bother to build blocks that aren't accessible. - if ($element['#access'] = $block->access()) { + if ($element['#access'] = $block->access('view')) { $element += entity_view($block, 'block'); } return $element;