additional, improved transformers / skipIf to eliminate records
This commit is contained in:
@@ -435,6 +435,90 @@ class ColumnTransformerTest extends TestCase
|
||||
$this->assertSame('Hello World', $result['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionAppendWithDelimiter(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append',
|
||||
'appendDelimiter' => ', ',
|
||||
], ['A' => 'World', 'B' => 'Hello']);
|
||||
$this->assertSame('Hello, World', $result['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionAppendWithDelimiterSkippedWhenTargetEmpty(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append',
|
||||
'appendDelimiter' => ', ',
|
||||
], ['A' => 'Hello', 'B' => '']);
|
||||
$this->assertSame('Hello', $result['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionAppendLine(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append-line',
|
||||
], ['A' => 'Line2', 'B' => 'Line1']);
|
||||
$this->assertSame("Line1\nLine2", $result['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionAppendLineNoLeadingNewlineWhenEmpty(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append-line',
|
||||
], ['A' => 'Line1', 'B' => '']);
|
||||
$this->assertSame('Line1', $result['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionOverwriteIfEmpty(): void
|
||||
{
|
||||
$resultEmpty = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'overwrite-if-empty',
|
||||
], ['A' => 'new', 'B' => '']);
|
||||
$this->assertSame('new', $resultEmpty['B']);
|
||||
|
||||
$resultFilled = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'overwrite-if-empty',
|
||||
], ['A' => 'new', 'B' => 'existing']);
|
||||
$this->assertSame('existing', $resultFilled['B']);
|
||||
}
|
||||
|
||||
public function testOutputActionOverwriteIfNotEmpty(): void
|
||||
{
|
||||
$resultNotEmpty = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'overwrite-if-not-empty',
|
||||
], ['A' => 'new', 'B' => 'old']);
|
||||
$this->assertSame('new', $resultNotEmpty['B']);
|
||||
|
||||
$resultEmpty = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'overwrite-if-not-empty',
|
||||
], ['A' => '', 'B' => 'old']);
|
||||
$this->assertSame('old', $resultEmpty['B']);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// multi-output split
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -504,4 +588,139 @@ class ColumnTransformerTest extends TestCase
|
||||
$transformer->transformRow(['A' => '1', 'B' => '2', 'C' => '3']);
|
||||
$this->assertSame(2, $transformer->getOutputColumns());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// timeperiod
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/** @var array<int, array<string, string>> */
|
||||
private array $testPeriods = [
|
||||
['from' => '04:00:00', 'to' => '08:59:59', 'label' => 'Morgen'],
|
||||
['from' => '09:00:00', 'to' => '10:59:59', 'label' => 'Vormittag'],
|
||||
['from' => '11:00:00', 'to' => '13:59:59', 'label' => 'Mittag'],
|
||||
['from' => '14:00:00', 'to' => '17:59:59', 'label' => 'Nachmittag'],
|
||||
['from' => '18:00:00', 'to' => '21:59:59', 'label' => 'Abend'],
|
||||
['from' => '22:00:00', 'to' => '03:59:59', 'label' => 'Nacht'],
|
||||
];
|
||||
|
||||
public function testTimePeriodBasicMapping(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'Time',
|
||||
'outputColumn' => 'Period',
|
||||
'type' => 'timeperiod',
|
||||
'timeFormat' => 'H:i:s',
|
||||
'periods' => $this->testPeriods,
|
||||
'default' => '',
|
||||
], ['Time' => '09:30:00', 'Period' => '']);
|
||||
$this->assertSame('Vormittag', $result['Period']);
|
||||
}
|
||||
|
||||
public function testTimePeriodMidnightSpanning(): void
|
||||
{
|
||||
$result1 = $this->applyOne([
|
||||
'sourceColumn' => 'Time',
|
||||
'outputColumn' => 'Period',
|
||||
'type' => 'timeperiod',
|
||||
'timeFormat' => 'H:i:s',
|
||||
'periods' => $this->testPeriods,
|
||||
'default' => '',
|
||||
], ['Time' => '23:00:00', 'Period' => '']);
|
||||
$this->assertSame('Nacht', $result1['Period']);
|
||||
|
||||
$result2 = $this->applyOne([
|
||||
'sourceColumn' => 'Time',
|
||||
'outputColumn' => 'Period',
|
||||
'type' => 'timeperiod',
|
||||
'timeFormat' => 'H:i:s',
|
||||
'periods' => $this->testPeriods,
|
||||
'default' => '',
|
||||
], ['Time' => '02:00:00', 'Period' => '']);
|
||||
$this->assertSame('Nacht', $result2['Period']);
|
||||
}
|
||||
|
||||
public function testTimePeriodNoMatch(): void
|
||||
{
|
||||
// 03:45 falls outside all labelled ranges except Nacht (00:00-03:59)
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'Time',
|
||||
'outputColumn' => 'Period',
|
||||
'type' => 'timeperiod',
|
||||
'timeFormat' => 'H:i:s',
|
||||
'periods' => [
|
||||
['from' => '09:00:00', 'to' => '17:59:59', 'label' => 'Day'],
|
||||
],
|
||||
'default' => 'Unknown',
|
||||
], ['Time' => '03:45:00', 'Period' => '']);
|
||||
$this->assertSame('Unknown', $result['Period']);
|
||||
}
|
||||
|
||||
public function testTimePeriodInvalidInput(): void
|
||||
{
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'Time',
|
||||
'outputColumn' => 'Period',
|
||||
'type' => 'timeperiod',
|
||||
'timeFormat' => 'H:i:s',
|
||||
'periods' => $this->testPeriods,
|
||||
'default' => 'N/A',
|
||||
], ['Time' => '', 'Period' => '']);
|
||||
$this->assertSame('N/A', $result['Period']);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ucwordsfirst guard
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function testUcwordsFirstSkipsLowercase(): void
|
||||
{
|
||||
// Input already contains lowercase letters → must be returned unchanged
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'A',
|
||||
'type' => 'ucwordsfirst',
|
||||
], ['A' => 'Coop pronto chur']);
|
||||
$this->assertSame('Coop pronto chur', $result['A']);
|
||||
}
|
||||
|
||||
public function testUcwordsFirstAppliesAllCaps(): void
|
||||
{
|
||||
// Fully uppercase input → capitalise first letter of each word
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'A',
|
||||
'type' => 'ucwordsfirst',
|
||||
], ['A' => 'COOP PRONTO']);
|
||||
$this->assertSame('Coop Pronto', $result['A']);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// append-if-not-empty
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function testAppendIfNotEmptySkipsEmpty(): void
|
||||
{
|
||||
// Result is empty → target column must remain unchanged
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append-if-not-empty',
|
||||
'appendDelimiter' => ' ',
|
||||
], ['A' => '', 'B' => 'existing']);
|
||||
$this->assertSame('existing', $result['B']);
|
||||
}
|
||||
|
||||
public function testAppendIfNotEmptyAppendsNonEmpty(): void
|
||||
{
|
||||
// Non-empty result → appended with delimiter
|
||||
$result = $this->applyOne([
|
||||
'sourceColumn' => 'A',
|
||||
'outputColumn' => 'B',
|
||||
'type' => 'map',
|
||||
'outputAction' => 'append-if-not-empty',
|
||||
'appendDelimiter' => ' ',
|
||||
], ['A' => 'new', 'B' => 'existing']);
|
||||
$this->assertSame('existing new', $result['B']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user