You are here

public function EntityFormTest::testSaveSettingsSetAndSave in Acquia Content Hub 8

Tests the saveSettings() method, actually set and save.

@covers ::saveSettings

@dataProvider providerTestSaveSettingsSetAndSave

Parameters

bool $old_auto_update_flag: Has local change flag.

int $new_auto_update_flag: Set to auto update flag.

string $method_name: The method name to be called before save().

string $method_parameter: The method parameter to be called before save().

File

tests/src/Unit/Form/EntityFormTest.php, line 296

Class

EntityFormTest
PHPUnit test for the EntityForm class.

Namespace

Drupal\Tests\acquia_contenthub\Unit\Form

Code

public function testSaveSettingsSetAndSave($old_auto_update_flag, $new_auto_update_flag, $method_name, $method_parameter) {
  $node = $this
    ->createMock('\\Drupal\\node\\NodeInterface');
  $node
    ->expects($this
    ->once())
    ->method('getEntityTypeId')
    ->willReturn('node');
  $node
    ->expects($this
    ->once())
    ->method('id')
    ->willReturn(12);
  $form_object = $this
    ->createMock('Drupal\\Core\\Entity\\EntityFormInterface');
  $form_object
    ->expects($this
    ->once())
    ->method('getEntity')
    ->willReturn($node);
  $form_state = $this
    ->createMock('Drupal\\Core\\Form\\FormState');
  $form_state
    ->expects($this
    ->once())
    ->method('isValueEmpty')
    ->willReturn(FALSE);
  $form_state
    ->expects($this
    ->once())
    ->method('getFormObject')
    ->willReturn($form_object);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('loadImportedByDrupalEntity')
    ->with('node', 12)
    ->willReturn($this->contentHubEntitiesTracking);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('isAutoUpdate')
    ->willReturn($old_auto_update_flag);
  $form_state
    ->expects($this
    ->once())
    ->method('getValue')
    ->with('acquia_contenthub')
    ->willReturn([
    'auto_update' => $new_auto_update_flag,
  ]);
  $method = $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method($method_name);
  if ($method_parameter) {
    $method
      ->with($method_parameter);
  }
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('save');
  $this->entityForm
    ->saveSettings($form_state);
}