-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restored original behavior of DOMElementValue function combined with …
…XPath
- Loading branch information
1 parent
e56255c
commit 0d02bdb
Showing
6 changed files
with
212 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
+----+------+--------+-------+ | ||
| id | name | active | email | | ||
+----+------+--------+-------+ | ||
| 1 | | | | | ||
| 2 | | | | | ||
| 3 | | | | | ||
| 4 | | | | | ||
| 5 | | | | | ||
| 6 | | | | | ||
| 7 | | | | | ||
| 8 | | | | | ||
| 9 | | | | | ||
| 10 | | | | | ||
+----+------+--------+-------+ | ||
+----+---------+--------+---------------------+ | ||
| id | name | active | email | | ||
+----+---------+--------+---------------------+ | ||
| 1 | Alice | true | alice@example.com | | ||
| 2 | Bob | false | bob@example.com | | ||
| 3 | Charlie | true | charlie@example.com | | ||
| 4 | David | false | david@example.com | | ||
| 5 | Emma | true | emma@example.com | | ||
| 6 | Frank | false | frank@example.com | | ||
| 7 | Grace | true | grace@example.com | | ||
| 8 | Harry | false | harry@example.com | | ||
| 9 | Isla | true | isla@example.com | | ||
| 10 | James | false | james@example.com | | ||
+----+---------+--------+---------------------+ | ||
10 rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/core/etl/tests/Flow/ETL/Tests/Integration/Function/DOMElementAttributeValueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Function; | ||
|
||
use function Flow\ETL\DSL\{df, from_rows, ref, row, rows, xml_element_entry, xml_entry}; | ||
use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; | ||
|
||
final class DOMElementAttributeValueTest extends TestCase | ||
{ | ||
public function test_dom_element_attribute_value() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_element_entry('node', '<name id="1">User Name 01</name>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_id', ref('node')->domElementAttributeValue('id')) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_id' => '1'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
|
||
public function test_dom_element_attribute_value_from_dom_document() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_entry('node', '<name id="1">User Name 01</name>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_id', ref('node')->domElementAttributeValue('id')) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_id' => '1'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
|
||
public function test_dom_element_attribute_value_on_xpath_result() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_entry('node', '<user><name id="1">User Name 01</name></user>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_id', ref('node')->xpath('name')->domElementAttributeValue('id')) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_id' => '1'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/core/etl/tests/Flow/ETL/Tests/Integration/Function/DOMElementValueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Function; | ||
|
||
use function Flow\ETL\DSL\{df, from_rows, ref, row, rows, xml_element_entry, xml_entry}; | ||
use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; | ||
|
||
final class DOMElementValueTest extends TestCase | ||
{ | ||
public function test_dom_element_value() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_element_entry('node', '<name>User Name 01</name>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_name', ref('node')->domElementValue()) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_name' => 'User Name 01'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
|
||
public function test_dom_element_value_from_dom_document() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_entry('node', '<name>User Name 01</name>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_name', ref('node')->domElementValue()) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_name' => 'User Name 01'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
|
||
public function test_dom_element_value_on_xpath_result() : void | ||
{ | ||
$rows = df() | ||
->read(from_rows( | ||
rows( | ||
row( | ||
xml_entry('node', '<user><name>User Name 01</name></user>') | ||
) | ||
) | ||
)) | ||
->withEntry('user_name', ref('node')->xpath('name')->domElementValue()) | ||
->drop('node') | ||
->fetch(); | ||
|
||
self::assertSame( | ||
[ | ||
['user_name' => 'User Name 01'], | ||
], | ||
$rows->toArray() | ||
); | ||
} | ||
} |