/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->keyValue = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreExpirableInterface'); $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface'); $this->currentUser = $this->getMock('Drupal\\Core\\Session\\AccountProxyInterface'); $this->currentUser->expects($this->any())->method('id')->willReturn(1); $this->requestStack = new RequestStack(); $this->tempStore = new PrivateTempStore($this->keyValue, $this->lock, $this->currentUser, $this->requestStack, 604800); $this->ownObject = (object) array('data' => 'test_data', 'owner' => $this->currentUser->id(), 'updated' => REQUEST_TIME); // Clone the object but change the owner. $this->otherObject = clone $this->ownObject; $this->otherObject->owner = 2; }
/** * @covers ::toArray */ public function testToArray() { $this->typedConfigManager->expects($this->once())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'dependencies' => '')))); $properties = $this->entity->toArray(); $this->assertInternalType('array', $properties); $this->assertEquals(array('id' => $this->entity->id(), 'dependencies' => array()), $properties); }
/** * @covers ::create() */ public function testCreate() { $language_manager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'); $this->container->set('language_manager', $language_manager); $this->container->set('entity.manager', $this->entityManager); $this->container->set('module_handler', $this->moduleHandler); $entity = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')->disableOriginalConstructor()->setMethods(array('id'))->getMockForAbstractClass(); $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue($this->entityTypeId)); $this->entityType->expects($this->atLeastOnce())->method('getClass')->will($this->returnValue(get_class($entity))); $this->entityType->expects($this->atLeastOnce())->method('getKeys')->will($this->returnValue(array('id' => 'id'))); // ContentEntityStorageBase iterates over the entity which calls this method // internally in ContentEntityBase::getProperties(). $this->entityManager->expects($this->once())->method('getFieldDefinitions')->will($this->returnValue(array())); $this->entityType->expects($this->atLeastOnce())->method('isRevisionable')->will($this->returnValue(FALSE)); $this->entityManager->expects($this->atLeastOnce())->method('getDefinition')->with($this->entityType->id())->will($this->returnValue($this->entityType)); $this->setUpEntityStorage(); $entity = $this->entityStorage->create(); $entity->expects($this->atLeastOnce())->method('id')->will($this->returnValue('foo')); $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity); $this->assertSame('foo', $entity->id()); $this->assertTrue($entity->isNew()); }
/** * @covers ::id */ public function testId() { $this->assertSame($this->values['id'], $this->entity->id()); }