nextcloud-gpodder/tests/Integration/EpisodeActionSaverGuidBackwardCompatibilityTest.php
Linus Kardell cd7ec988f2 Fix getId() on null in deleteConflictingEpisodeAction
Previously, it would take the guid and try to search for that in the
episode URL column, which may not find a match (or possibly even find
the wrong match).

testDoNotFailToUpdateEpisodeActionByGuidIfThereIsAnotherWithTheSameValueForEpisodeUrl
didn't catch this issue because it used the same value for episode and
guid when updating at line 84, so fix that as well. And for good
measure, give the save actions different position values, so the asserts
actually check that the saves have succeeded and they found the right
episode.
2024-01-12 20:43:01 +01:00

96 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
namespace tests\Integration;
use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionSaver;
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
use OCP\AppFramework\App;
use Test\TestCase;
/**
* @group DB
*/
class EpisodeActionSaverGuidBackwardCompatibilityTest extends TestCase
{
private const USER_ID_0 = "testuser0";
private \OCP\AppFramework\IAppContainer $container;
public function setUp(): void
{
parent::setUp();
$app = new App('gpoddersync');
$this->container = $app->getContainer();
}
public function testUpdateWithoutGuidDoesNotNullGuid(): void
{
/** @var EpisodeActionSaver $episodeActionSaver */
$episodeActionSaver = $this->container->get(EpisodeActionSaver::class);
$episodeUrl = uniqid("test_https://dts.podtrac.com/redirect.mp3/chrt.fm/track");
$guid = uniqid("test_gid://art19-episode-locator/V0/Ktd");
$savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions(
[["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "guid" => $guid, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]],
self::USER_ID_0
)[0];
$savedEpisodeActionEntityWithoutGuidFromOldDevice = $episodeActionSaver->saveEpisodeActions(
[["podcast" => 'https://rss.art19.com/dr-death-s3-miracle-man', "episode" => $episodeUrl, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 47, "position" => 54, "total" => 2252]],
self::USER_ID_0
)[0];
self::assertSame($savedEpisodeActionEntity->getId(), $savedEpisodeActionEntityWithoutGuidFromOldDevice->getId());
self::assertNotNull($savedEpisodeActionEntityWithoutGuidFromOldDevice->getGuid());
}
public function testDoNotFailToUpdateEpisodeActionByGuidIfThereIsAnotherWithTheSameValueForEpisodeUrl(): void
{
//arrange
/** @var EpisodeActionSaver $episodeActionSaver */
$episodeActionSaver = $this->container->get(EpisodeActionSaver::class);
$url = uniqid("https://podcast-mp3.dradio.de/");
$urlWithParameter = $url . "?ref=never_know_if_ill_be_removed";
$guid1 = uniqid("quid1");
$guid2 = uniqid("quid2");
$podcastUrl = uniqid("https://podcast");
$episodeActionSaver->saveEpisodeActions(
[["podcast" => $podcastUrl, "episode" => $url, "guid" => $guid2, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 100, "total" => 2252]],
self::USER_ID_0
)[0];
$episodeActionSaver->saveEpisodeActions(
[["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid1, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 101, "total" => 2252]],
self::USER_ID_0
)[0];
//act
$episodeActionSaver->saveEpisodeActions(
[["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid1, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 102, "total" => 2252]],
self::USER_ID_0
)[0];
//assert
/** @var EpisodeActionRepository $episodeActionRepository */
$episodeActionRepository = $this->container->get(EpisodeActionRepository::class);
$this->assertSame(100, $episodeActionRepository->findByGuid($guid2, self::USER_ID_0)->getPosition());
//act
$episodeActionSaver->saveEpisodeActions(
[["podcast" => $podcastUrl, "episode" => $urlWithParameter, "guid" => $guid2, "action" => "PLAY", "timestamp" => "2021-08-22T23:58:56", "started" => 35, "position" => 103, "total" => 2252]],
self::USER_ID_0
)[0];
//assert
/** @var EpisodeActionRepository $episodeActionRepository */
$episodeActionRepository = $this->container->get(EpisodeActionRepository::class);
$this->assertSame(103, $episodeActionRepository->findByGuid($guid2, self::USER_ID_0)->getPosition());
}
}