class ParagraphsProcessOnValueTest

Test class for the paragraphs_process_on_value process plugin.

@group paragraphs @coversDefaultClass \Drupal\paragraphs\Plugin\migrate\process\ParagraphsProcessOnValue

Hierarchy

Expanded class hierarchy of ParagraphsProcessOnValueTest

File

paragraphs/tests/src/Unit/migrate/ParagraphsProcessOnValueTest.php, line 17

Namespace

Drupal\Tests\paragraphs\Unit\migrate
View source
class ParagraphsProcessOnValueTest extends ProcessTestCase {

  /**
   * {@inheritdoc}
   */
  protected $migrationConfiguration = [
    'id' => 'test',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setup();
    $configuration = [
      'source_value' => 'source',
      'expected_value' => 'expected',
      'process' => [
        'plugin' => 'get',
        'source' => 'theValue',
      ],
    ];
    $this->plugin = new ParagraphsProcessOnValue($configuration, 'paragraphs_process_on_value', [], $this->entityTypeBundleInfo);
    $this->row
      ->expects($this
      ->any())
      ->method('getSource')
      ->willReturn([
      'theValue' => 'Final Value',
      'source' => 'expected',
    ]);
  }

  /**
   * Test processing if conditions are met.
   */
  public function testProcess() {
    $migration = $this
      ->getMigration();
    $get = new Get([
      'source' => 'theValue',
    ], 'get', []);
    $migration
      ->expects($this
      ->any())
      ->method('getProcessPlugins')
      ->willReturn([
      'destination' => [
        $get,
      ],
    ]);
    $this->row
      ->expects($this
      ->any())
      ->method('getSourceProperty')
      ->with('source')
      ->willReturn('expected');
    $event_dispatcher = $this
      ->createMock(EventDispatcherInterface::class);
    $message = $this
      ->createMock(MigrateMessageInterface::class);
    $migrate_executable = new MigrateExecutable($migration, $message, $event_dispatcher);
    $value = $this->plugin
      ->transform('Initial Value', $migrate_executable, $this->row, 'destination');
    $this
      ->assertEquals('Final Value', $value);
  }

  /**
   * Test not processing if conditions are not met.
   */
  public function testSkip() {
    $migration = $this
      ->getMigration();
    $get = new Get([
      'source' => 'theValue',
    ], 'get', []);
    $migration
      ->expects($this
      ->any())
      ->method('getProcessPlugins')
      ->willReturn([
      'destination' => [
        $get,
      ],
    ]);
    $this->row
      ->expects($this
      ->any())
      ->method('getSourceProperty')
      ->with('source')
      ->willReturn('unexpected');
    $event_dispatcher = $this
      ->createMock(EventDispatcherInterface::class);
    $message = $this
      ->createMock(MigrateMessageInterface::class);
    $migrate_executable = new MigrateExecutable($migration, $message, $event_dispatcher);
    $value = $this->plugin
      ->transform('Initial Value', $migrate_executable, $this->row, 'destination');
    $this
      ->assertEquals('Initial Value', $value);
  }

}

Members

Name Modifiers Type Description Overridessort ascending
ParagraphsProcessOnValueTest::setUp public function Overrides ProcessTestCase::setUp
ParagraphsProcessOnValueTest::testProcess public function Test processing if conditions are met.
ParagraphsProcessOnValueTest::testSkip public function Test not processing if conditions are not met.
ParagraphsProcessOnValueTest::$migrationConfiguration protected property
ProcessTestCase::$entityTypeBundleInfo protected property The entity bundle info service.