Files
XC_VM/tests/Unit/M3uParser/M3uDataTest.php
T
Divarion-D d8a48520fe feat(stream): migrate to vendored M3uParser and add parser/import tests
- Replace legacy in-project M3U parser with vendored Gemorroj/M3uParser
- Initialize parser via bootstrap with proper namespacing
- Remove obsolete src/domain/Stream/M3UEntry.php implementation

- Update stream import/review mapping:
  - use logo as fallback when tvg-logo is missing

- Add third-party compliance files for vendored parser:
  - ATTRIBUTION.md
  - LGPL LICENSE

- Add full M3uParser unit test suite:
  - tag parsing
  - parser behavior
  - fixtures

- Add StreamService integration tests for M3U parsing/import flow

- Update test bootstrap:
  - add igbinary_serialize / igbinary_unserialize polyfills
  - explicitly load M3uParser bootstrap and custom test tag class
2026-04-21 14:52:46 +03:00

112 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace M3uParser\Tests;
use M3uParser\M3uData;
use M3uParser\M3uEntry;
use M3uParser\Tag\ExtInf;
use M3uParser\Tag\ExtLogo;
use M3uParser\Tag\ExtTv;
use PHPUnit\Framework\TestCase;
class M3uDataTest extends TestCase
{
public function testComplexDefaultEntryToString(): void
{
$expectedString = '#EXTM3U test-name="test-value"'."\n";
$expectedString .= '#EXTINF:123 test-attr="test-attrname",extinf-title'."\n";
$expectedString .= '#EXTTV:hd,sd;ru;xml-tv-id;https://example.org/icon.png'."\n";
$expectedString .= '#EXTLOGO:https://example.org/logo.png'."\n";
$expectedString .= 'test-path';
$entry = new M3uEntry();
$entry->setPath('test-path');
$entry->addExtTag(
(new ExtInf())
->setDuration(123)
->setTitle('extinf-title')
->setAttribute('test-attr', 'test-attrname')
);
$entry->addExtTag(
(new ExtTv())
->setIconUrl('https://example.org/icon.png')
->setLanguage('ru')
->setXmlTvId('xml-tv-id')
->setTags(['hd', 'sd'])
);
$entry->addExtTag(
(new ExtLogo())
->setValue('https://example.org/logo.png')
);
$data = new M3uData();
$data->setAttribute('test-name', 'test-value');
$data->append($entry);
self::assertEquals($expectedString, (string) $data);
}
/**
* @see https://github.com/Gemorroj/M3uParser/pull/14
*/
public function testComplexDefaultEntriesToString(): void
{
$expectedString = '#EXTM3U test-name="test-value"'."\n";
$expectedString .= '#EXTINF:123 test-attr="test-attrname1",extinf-title1'."\n";
$expectedString .= '#EXTTV:hd,sd;ru;xml-tv-id;https://example.org/icon.png'."\n";
$expectedString .= '#EXTLOGO:https://example.org/logo.png'."\n";
$expectedString .= 'test-path1'."\n";
$expectedString .= '#EXTINF:123 test-attr="test-attrname2",extinf-title2'."\n";
$expectedString .= '#EXTTV:hd,sd;ru;xml-tv-id;https://example.org/icon.png'."\n";
$expectedString .= '#EXTLOGO:https://example.org/logo.png'."\n";
$expectedString .= 'test-path2';
$entry1 = new M3uEntry();
$entry1->setPath('test-path1');
$entry1->addExtTag(
(new ExtInf())
->setDuration(123)
->setTitle('extinf-title1')
->setAttribute('test-attr', 'test-attrname1')
);
$entry1->addExtTag(
(new ExtTv())
->setIconUrl('https://example.org/icon.png')
->setLanguage('ru')
->setXmlTvId('xml-tv-id')
->setTags(['hd', 'sd'])
);
$entry1->addExtTag(
(new ExtLogo())
->setValue('https://example.org/logo.png')
);
$entry2 = new M3uEntry();
$entry2->setPath('test-path2');
$entry2->addExtTag(
(new ExtInf())
->setDuration(123)
->setTitle('extinf-title2')
->setAttribute('test-attr', 'test-attrname2')
);
$entry2->addExtTag(
(new ExtTv())
->setIconUrl('https://example.org/icon.png')
->setLanguage('ru')
->setXmlTvId('xml-tv-id')
->setTags(['hd', 'sd'])
);
$entry2->addExtTag(
(new ExtLogo())
->setValue('https://example.org/logo.png')
);
$data = new M3uData([$entry1, $entry2]);
$data->setAttribute('test-name', 'test-value');
self::assertEquals($expectedString, (string) $data);
}
}