You are here

public function ProcessEntitiesTest::setUp in Field Encryption 3.0.x

Overrides UnitTestCase::setUp

File

tests/src/Unit/ProcessEntitiesTest.php, line 47

Class

ProcessEntitiesTest
Unit Tests for the ProcessEntities service.

Namespace

Drupal\Tests\field_encrypt\Unit

Code

public function setUp() {
  parent::setUp();
  if (version_compare(Version::id(), '8.0', '<')) {
    $this
      ->markTestSkipped('This test needs PHPUnit 8');
  }

  // 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\\LanguageInterface')
    ->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('getTranslationLanguages')
    ->will($this
    ->returnValue([
    $language,
  ]));
  $this->entity
    ->expects($this
    ->any())
    ->method('getTranslation')
    ->will($this
    ->returnSelf());

  // Set up a mock field.
  $this->field = $this
    ->getMockBuilder('\\Drupal\\Core\\Field\\FieldItemListInterface')
    ->disableOriginalConstructor()
    ->getMock();

  // Set up a mock storage field.
  $storage_item = $this
    ->getMockBuilder(EncryptedFieldStorageItem::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->storageField = $this
    ->getMockBuilder('\\Drupal\\Core\\Field\\FieldItemListInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $this->storageField
    ->expects($this
    ->any())
    ->method('offsetGet')
    ->with(0)
    ->willReturn($storage_item);
}