public function EncryptedFieldValueManagerTest::setUp in Field Encryption 8.2
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ EncryptedFieldValueManagerTest.php, line 55 - Contains \Drupal\Tests\field_encrypt\Unit\EncryptedFieldValueManagerTest.
Class
- EncryptedFieldValueManagerTest
- Unit Tests for the EncryptedFieldValueManager service.
Namespace
Drupal\Tests\field_encrypt\UnitCode
public function setUp() {
parent::setup();
// Set up a mock entity type manager service.
$this->entityManager = $this
->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface')
->disableOriginalConstructor()
->getMock();
// Set up a mock EntityStorage.
$this->storage = $this
->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')
->disableOriginalConstructor()
->getMock();
// Set up expectations for the entity type manager.
$this->entityManager
->expects($this
->any())
->method('getStorage')
->will($this
->returnValue($this->storage));
// Set up a mock entity.
$this->entity = $this
->getMockBuilder('\\Drupal\\Core\\Entity\\ContentEntityInterface')
->disableOriginalConstructor()
->getMock();
// Set up language object.
$language = $this
->getMockBuilder('\\Drupal\\Core\\Language\\Language')
->setMethods([
'getId',
])
->disableOriginalConstructor()
->getMock();
// Set up expectations for language.
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('en'));
// Set up expectations for entity.
$this->entity
->expects($this
->any())
->method('language')
->will($this
->returnValue($language));
$this->entity
->expects($this
->any())
->method('getEntityTypeId')
->will($this
->returnValue('node'));
$this->entity
->expects($this
->any())
->method('getRevisionId')
->will($this
->returnValue(2));
// Set up EncryptedFieldValue.
$this->encryptedFieldValue = $this
->getMockBuilder('\\Drupal\\field_encrypt\\Entity\\EncryptedFieldValue')
->setMethods([
'getEncryptedValue',
'hasTranslation',
'getTranslation',
'setEncryptedValue',
'save',
])
->disableOriginalConstructor()
->getMock();
// Set up expectations for EncryptedFieldValue.
$this->encryptedFieldValue
->expects($this
->any())
->method('hasTranslation')
->will($this
->returnValue(TRUE));
$this->encryptedFieldValue
->expects($this
->any())
->method('getTranslation')
->will($this
->returnSelf());
}