Files
kupshop/bundles/KupShop/FeedsBundle/Tests/FeedsTest.php
2025-08-02 16:30:27 +02:00

66 lines
2.0 KiB
PHP

<?php
namespace KupShop\FeedsBundle\Tests;
use KupShop\FeedsBundle\FeedLocator;
use KupShop\FeedsBundle\Utils\FeedUtils;
class FeedsTest extends \DatabaseTestCase
{
/** @var FeedLocator */
protected $feedLocator;
/** @var FeedUtils */
protected $feedUtils;
protected static $fakeTimestamp = '1509435085';
protected function setUp(): void
{
parent::setUp();
$this->feedLocator = $this->get(FeedLocator::class);
$this->feedUtils = $this->get(FeedUtils::class);
}
public function getDataSet()
{
return $this->getJsonDataSetFromFile(__DIR__.'/dataSet.json');
}
public function data_testFeeds()
{
// (int) ID, (string) type, (string) test xml file name, (bool) setTimestamp
// ID and type must match dataSet.json
return [
[10, 'configurable', 'configurable_heureka.xml'],
[11, 'configurable', 'configurable_seznam.xml'],
[12, 'configurable', 'configurable_heureka_s_darky.xml'],
];
}
/**
* @dataProvider data_testFeeds
*
* @throws \KupShop\FeedsBundle\Exceptions\UnknownFeedTypeException
*/
public function testFeeds(int $feedID, string $type, string $template, bool $setTimestamp = false)
{
ob_start();
$feed = $this->feedLocator->getServiceByType($type);
if ($setTimestamp) {
$feed->setTimestamp(static::$fakeTimestamp);
}
$feedRow = $this->selectSQL('feeds', ['id' => $feedID])->fetch();
$feedRow['data'] = json_decode($feedRow['data'] ?? '{}', true);
$feedRow['pretty'] = ($feedRow['data']['format'] ?? 'xml') == 'xml_pretty';
$this->feedUtils->prepareContexts($feedRow);
$feed->render($feedRow);
$output = ob_get_contents();
ob_end_clean();
// for new feed
// file_put_contents(__DIR__.'/'.$template, $output);
self::assertXmlStringEqualsXmlFile(__DIR__.'/'.$template, $output, $type.' -> '.$template);
}
}