Strip namespaces from namespaced XML plugin response, so we get usuable output

This commit is contained in:
Jamie Shiell 2026-02-08 16:39:03 +00:00 committed by Benjamin Nussbaum
parent 0aa38428f6
commit afc29e15d5
2 changed files with 50 additions and 2 deletions

View file

@ -36,7 +36,7 @@ test('plugin parses JSON responses correctly', function (): void {
]);
});
test('plugin parses XML responses and wraps under rss key', function (): void {
test('plugin parses RSS XML responses and wraps under rss key', function (): void {
$xmlContent = '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
@ -73,6 +73,33 @@ test('plugin parses XML responses and wraps under rss key', function (): void {
expect($plugin->data_payload['rss']['channel']['item'])->toHaveCount(2);
});
test('plugin parses namespaces XML responses and wraps under root key', function (): void {
$xmlContent = '<?xml version="1.0" encoding="UTF-8"?>
<foo:cake version="2.0" xmlns:foo="http://example.com/foo">
<bar:icing xmlns:bar="http://example.com/bar">
<ontop>Cherry</ontop>
</bar:icing>
</foo:cake>';
Http::fake([
'example.com/namespace.xml' => Http::response($xmlContent, 200, ['Content-Type' => 'application/xml']),
]);
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => 'https://example.com/namespace.xml',
'polling_verb' => 'get',
]);
$plugin->updateDataPayload();
$plugin->refresh();
expect($plugin->data_payload)->toHaveKey('rss');
expect($plugin->data_payload['rss'])->toHaveKey('icing');
expect($plugin->data_payload['rss']['icing']['ontop'])->toBe('Cherry');
});
test('plugin parses JSON-parsable response body as JSON', function (): void {
$jsonContent = '{"title": "Test Data", "items": [1, 2, 3]}';