/** * @covers ::create * @covers ::doCreate * * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { $this->cacheTagsInvalidator->expects($this->never())->method('invalidateTags'); $this->moduleHandler->expects($this->at(0))->method('invokeAll')->with('test_entity_type_create'); $this->moduleHandler->expects($this->at(1))->method('invokeAll')->with('entity_create'); $this->uuidService->expects($this->once())->method('generate')->will($this->returnValue('bar')); $entity = $this->entityStorage->create(array('id' => 'foo')); $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity); $this->assertSame('foo', $entity->id()); $this->assertSame('bar', $entity->uuid()); return $entity; }
/** * @covers ::create * @covers ::doCreate * * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { $entity = $this->getMockEntity('Drupal\\Core\\Entity\\Entity', array(), array('toArray')); $this->entityType->expects($this->once())->method('getClass')->will($this->returnValue(get_class($entity))); $this->setUpKeyValueEntityStorage(); $this->moduleHandler->expects($this->at(0))->method('invokeAll')->with('test_entity_type_create'); $this->moduleHandler->expects($this->at(1))->method('invokeAll')->with('entity_create'); $this->uuidService->expects($this->once())->method('generate')->will($this->returnValue('bar')); $entity = $this->entityStorage->create(array('id' => 'foo')); $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity); $this->assertSame('foo', $entity->id()); $this->assertSame('bar', $entity->uuid()); return $entity; }
/** * @covers ::createDuplicate */ public function testCreateDuplicate() { $this->entityType->expects($this->at(0))->method('getKey')->with('id')->will($this->returnValue('id')); $this->entityType->expects($this->at(1))->method('hasKey')->with('uuid')->will($this->returnValue(TRUE)); $this->entityType->expects($this->at(2))->method('getKey')->with('uuid')->will($this->returnValue('uuid')); $new_uuid = '8607ef21-42bc-4913-978f-8c06207b0395'; $this->uuid->expects($this->once())->method('generate')->will($this->returnValue($new_uuid)); $duplicate = $this->entity->createDuplicate(); $this->assertInstanceOf('\\Drupal\\Core\\Entity\\Entity', $duplicate); $this->assertNotSame($this->entity, $duplicate); $this->assertFalse($this->entity->isNew()); $this->assertTrue($duplicate->isNew()); $this->assertNull($duplicate->id()); $this->assertNull($duplicate->getOriginalId()); $this->assertNotEquals($this->entity->uuid(), $duplicate->uuid()); $this->assertSame($new_uuid, $duplicate->uuid()); }