View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\migrate\process\SkipOnEmpty;
class SkipOnEmptyTest extends MigrateProcessTestCase {
public function testProcessSkipsOnEmpty() {
$configuration['method'] = 'process';
$this
->expectException(MigrateSkipProcessException::class);
(new SkipOnEmpty($configuration, 'skip_on_empty', []))
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
}
public function testProcessBypassesOnNonEmpty() {
$configuration['method'] = 'process';
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
->transform(' ', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame(' ', $value);
}
public function testRowSkipsOnEmpty() {
$configuration['method'] = 'row';
$this
->expectException(MigrateSkipRowException::class);
(new SkipOnEmpty($configuration, 'skip_on_empty', []))
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
}
public function testRowBypassesOnNonEmpty() {
$configuration['method'] = 'row';
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
->transform(' ', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame(' ', $value);
}
public function testRowSkipWithoutMessage() {
$configuration = [
'method' => 'row',
];
$process = new SkipOnEmpty($configuration, 'skip_on_empty', []);
$this
->expectException(MigrateSkipRowException::class);
$process
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
}
public function testRowSkipWithMessage() {
$configuration = [
'method' => 'row',
'message' => 'The value is empty',
];
$process = new SkipOnEmpty($configuration, 'skip_on_empty', []);
$this
->expectException(MigrateSkipRowException::class);
$this
->expectExceptionMessage('The value is empty');
$process
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
}
}