2021-08-24 20:48:46 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace tests\Integration;
|
|
|
|
|
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionEntity;
|
2021-08-24 21:19:21 +00:00
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
2021-08-24 20:48:46 +00:00
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter;
|
|
|
|
use OCP\AppFramework\App;
|
2021-10-05 10:30:52 +00:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
2021-08-24 20:48:46 +00:00
|
|
|
use Test\TestCase;
|
|
|
|
use tests\Helper\DatabaseTransaction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DB
|
|
|
|
*/
|
|
|
|
class EpisodeActionGuidMigrationTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransaction;
|
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
private const USER_ID_0 = "user0@127.0.0.1";
|
|
|
|
|
2021-10-05 10:30:52 +00:00
|
|
|
private IAppContainer $container;
|
2021-08-24 20:48:46 +00:00
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
/**
|
|
|
|
* @var EpisodeActionWriter
|
|
|
|
*/
|
|
|
|
private $episodeActionWriter;
|
|
|
|
|
2021-08-25 17:33:00 +00:00
|
|
|
/**
|
|
|
|
* @var EpisodeActionRepository
|
|
|
|
*/
|
|
|
|
private $episodeActionRepository;
|
|
|
|
|
2021-08-24 20:48:46 +00:00
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$app = new App('gpoddersync');
|
|
|
|
$this->container = $app->getContainer();
|
2021-08-24 21:19:21 +00:00
|
|
|
$this->episodeActionWriter = $this->container->get(EpisodeActionWriter::class);
|
2021-08-25 17:33:00 +00:00
|
|
|
$this->episodeActionRepository = $this->container->get(EpisodeActionRepository::class);
|
2021-08-24 20:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @before
|
|
|
|
*/
|
|
|
|
public function before()
|
|
|
|
{
|
|
|
|
$this->startTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateSameEpisodeActionTriggersUniqueConstraintViolationException()
|
|
|
|
{
|
2021-10-05 18:49:13 +00:00
|
|
|
self::expectExceptionMessageMatches(
|
2021-10-06 17:27:08 +00:00
|
|
|
"/(unique constraint|Integrity constraint violation)/"
|
2021-10-05 18:49:13 +00:00
|
|
|
);
|
2021-08-24 20:48:46 +00:00
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
$episodeActionEntity = new EpisodeActionEntity();
|
|
|
|
$episodeActionEntity->setPodcast("https://podcast_01.url");
|
|
|
|
$episodeActionEntity->setEpisode("https://episode_01.url");
|
|
|
|
$episodeActionEntity->setAction("PLAY");
|
|
|
|
$episodeActionEntity->setPosition(5);
|
|
|
|
$episodeActionEntity->setStarted(0);
|
|
|
|
$episodeActionEntity->setTotal(123);
|
2021-10-05 21:33:06 +00:00
|
|
|
$episodeActionEntity->setTimestampEpoch(1629676736);
|
2021-08-24 21:19:21 +00:00
|
|
|
$episodeActionEntity->setUserId(self::USER_ID_0);
|
|
|
|
$this->episodeActionWriter->save($episodeActionEntity);
|
|
|
|
|
|
|
|
//and save again
|
|
|
|
$this->episodeActionWriter->save($episodeActionEntity);
|
2021-08-24 20:48:46 +00:00
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindEpisodeActionByEpisodeUrlAndThenGuid()
|
|
|
|
{
|
2021-08-24 20:48:46 +00:00
|
|
|
$episodeActionEntity = new EpisodeActionEntity();
|
|
|
|
$episodeActionEntity->setPodcast("https://podcast_01.url");
|
|
|
|
$episodeActionEntity->setEpisode("https://episode_01.url");
|
|
|
|
$episodeActionEntity->setAction("PLAY");
|
|
|
|
$episodeActionEntity->setPosition(5);
|
|
|
|
$episodeActionEntity->setStarted(0);
|
|
|
|
$episodeActionEntity->setTotal(123);
|
2021-10-05 21:33:06 +00:00
|
|
|
$episodeActionEntity->setTimestampEpoch(1629676736);
|
2021-08-24 21:19:21 +00:00
|
|
|
$episodeActionEntity->setUserId(self::USER_ID_0);
|
|
|
|
$savedEpisodeActionEntity = $this->episodeActionWriter->save($episodeActionEntity);
|
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
$savedEpisodeActionEntity->getId(),
|
2021-08-25 17:33:00 +00:00
|
|
|
$this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntity->getEpisode(), self::USER_ID_0)->getId()
|
2021-08-24 21:19:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//update same episode action again this time with guid
|
|
|
|
|
|
|
|
$episodeActionEntityWithGuid = clone $episodeActionEntity;
|
|
|
|
$episodeActionEntityWithGuid->setGuid("guid:dadsaf4f4v");
|
|
|
|
$savedEpisodeActionEntityWithGuid = $this->episodeActionWriter->update($episodeActionEntityWithGuid);
|
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
$savedEpisodeActionEntityWithGuid->getId(),
|
2021-08-25 17:33:00 +00:00
|
|
|
$this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntityWithGuid->getEpisode(), self::USER_ID_0)->getId()
|
2021-08-24 21:19:21 +00:00
|
|
|
);
|
2021-08-24 20:48:46 +00:00
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
self::assertSame(
|
|
|
|
$savedEpisodeActionEntityWithGuid->getId(),
|
2021-08-25 17:33:00 +00:00
|
|
|
$this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntityWithGuid->getGuid(), self::USER_ID_0)->getId()
|
2021-08-24 21:19:21 +00:00
|
|
|
);
|
2021-08-24 20:48:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @after
|
|
|
|
*/
|
|
|
|
public function after()
|
|
|
|
{
|
|
|
|
$this->rollbackTransation();
|
|
|
|
}
|
|
|
|
}
|