laminas / laminas-feed

Consume and generate Atom and RSS feeds, and interact with Pubsubhubbub.

Home Page:https://docs.laminas.dev/laminas-feed/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Itunes categories with same main category are overwritten

podcasthosting opened this issue · comments

Bug Report

Q A
Version(s) 2.14.1

Summary

When setting multiple iTunes categories and two or more having the same "main" category the latter are overwritten.

Current behavior

$feed->setItunesCategories(['Arts' => 'Food]);
$feed->setItunesCategories(['Arts' => 'Visual Arts]);

only

    <itunes:category text="Arts">
      <itunes:category text="Visual Arts"/>
    </itunes:category>

ends up being in the rendered output

How to reproduce

Add two categories with the same main category.

Expected behavior

I´d expect both entries being shown in the feed.

    <itunes:category text="Arts">
      <itunes:category text="Food"/>
    </itunes:category>
    <itunes:category text="Arts">
      <itunes:category text="Visual Arts"/>
    </itunes:category>

The culprit seems to be

vendor/laminas/laminas-feed/src/Writer/Extension/ITunes/Feed.php

somewhere within method setItunesCategories()

@podcasthosting

$feed->setItunesCategories(['Arts' => 'Food']);
$feed->setItunesCategories(['Arts' => 'Visual Arts']);

The usage is wrong because the method sets all categories for the feed and a second call overwrites all previous categories. You expect the functionality of a method like addItunesCategory but it does not exist.

Use the following:

$feed->setItunesCategories(['Arts' => ['Food', 'Visual Arts']]);

But why does it work with categories with a different main category?

$feed->setItunesCategories(['Arts' => 'Food]);
$feed->setItunesCategories(['Business']);
$feed->setItunesCategories(['Comedy' => 'Comedy Interviews']);

Adds all 3 categories to the feed (as expected). Right now it partly works like an addItunesCategory method.

@podcasthosting
The method is far from perfect and leads to unexpected behaviour at the moment. A clean and well-defined API is needed to avoid problems like the current one.

Adds all 3 categories to the feed (as expected). Right now it partly works like an addItunesCategory method.

And this behaviour is wrong. setItunesCategories should set the categories in whole and should overwrite all previous categories.

But at this point, we cannot change the current behaviour because this could break the current running applications.

Thank you for clarification!

@podcasthosting
I would leave the issue report open because the API can be improved with the next major version. That's why I had added the milestone.

This actually also does not work:

$feed->setItunesCategories(['Comedy' => ['Improv', 'Comedy Interviews']]);

The result is:

    <itunes:category text="Comedy">
      <itunes:category text="Improv"/>
      <itunes:category text="Comedy Interviews"/>
    </itunes:category>

but should be:

    <itunes:category text="Comedy">
      <itunes:category text="Improv"/>
    </itunes:category>

    <itunes:category text="Comedy">
      <itunes:category text="Comedy Interviews"/>
    </itunes:category>

So this is completely broken and a pretty severe bug (from our customers` point of view).

@podcasthosting

but should be:

    <itunes:category text="Comedy">
      <itunes:category text="Improv"/>
    </itunes:category>

    <itunes:category text="Comedy">
      <itunes:category text="Comedy Interviews"/>
    </itunes:category>

Can you provide a reference / documentation for this? Thanks in advance! 👍

@podcasthosting
Another idea is to use the corresponding XML schemas in the unit tests, so the schemas will also help here.

@podcasthosting
Did you find some reference or documentation for this topic?