2021-10-05 10:30:52 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace tests\Integration\Migration;
|
|
|
|
|
2021-10-05 21:24:12 +00:00
|
|
|
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
|
2021-10-05 10:30:52 +00:00
|
|
|
use OC\AllConfig;
|
|
|
|
use OC\Migration\SimpleOutput;
|
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionEntity;
|
2021-10-05 18:45:06 +00:00
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionMapper;
|
2021-10-05 10:30:52 +00:00
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter;
|
|
|
|
use OCA\GPodderSync\Migration\TimestampMigration;
|
|
|
|
use OCP\AppFramework\App;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use test\TestCase;
|
|
|
|
use tests\Helper\DatabaseTransaction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DB
|
|
|
|
*/
|
|
|
|
class TimestampMigrationTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransaction;
|
|
|
|
|
|
|
|
const TEST_GUID_1234 = "test_uuid_1234";
|
|
|
|
const ADMIN = "admin";
|
|
|
|
private EpisodeActionWriter $episodeActionWriter;
|
2021-10-05 18:45:06 +00:00
|
|
|
private EpisodeActionMapper $episodeActionMapper;
|
2021-10-05 10:30:52 +00:00
|
|
|
private IDBConnection $dbConnection;
|
|
|
|
private IConfig $migrationConfig;
|
|
|
|
|
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$app = new App('gpoddersync');
|
2021-10-06 12:02:31 +00:00
|
|
|
$container = $app->getContainer();
|
|
|
|
$this->episodeActionWriter = $container->get(EpisodeActionWriter::class);
|
|
|
|
$this->episodeActionMapper = $container->get(EpisodeActionMapper::class);
|
|
|
|
$this->dbConnection = $container->get(IDBConnection::class);
|
|
|
|
$this->migrationConfig = $container->get(AllConfig::class );
|
2021-10-05 10:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @before
|
|
|
|
*/
|
|
|
|
public function before()
|
|
|
|
{
|
|
|
|
$this->startTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTimestampConversionRepairStep()
|
|
|
|
{
|
2021-10-05 21:24:12 +00:00
|
|
|
if (!$this->dbConnection->getDatabasePlatform() instanceof PostgreSQL100Platform) {
|
|
|
|
self::markTestSkipped("This test only works on postgres");
|
|
|
|
}
|
|
|
|
|
2021-10-13 17:59:31 +00:00
|
|
|
$scienceEpisodeActionEntity = new EpisodeActionEntity();
|
|
|
|
$scienceEpisodeActionEntity->setPodcast("https://podcast_01.url");
|
|
|
|
$scienceEpisodeActionEntity->setEpisode(uniqid("https://episode_01.url"));
|
|
|
|
$scienceEpisodeActionEntity->setAction("PLAY");
|
|
|
|
$scienceEpisodeActionEntity->setPosition(5);
|
|
|
|
$scienceEpisodeActionEntity->setStarted(0);
|
|
|
|
$scienceEpisodeActionEntity->setTotal(123);
|
|
|
|
$scienceEpisodeActionEntity->setTimestamp("2021-08-22T23:58:56");
|
|
|
|
$scienceEpisodeActionEntity->setUserId(self::ADMIN);
|
|
|
|
$scienceEpisodeActionEntity->setGuid(uniqid("self::TEST_GUID_1234"));
|
|
|
|
$this->episodeActionWriter->save($scienceEpisodeActionEntity);
|
|
|
|
|
|
|
|
$trueCrimeEpisodeActionEntity = new EpisodeActionEntity();
|
|
|
|
$trueCrimeEpisodeActionEntity->setPodcast(uniqid("podcast"));
|
|
|
|
$trueCrimeEpisodeActionEntity->setEpisode(uniqid("episode_url"));
|
|
|
|
$trueCrimeEpisodeActionEntity->setAction("PLAY");
|
|
|
|
$trueCrimeEpisodeActionEntity->setPosition(5);
|
|
|
|
$trueCrimeEpisodeActionEntity->setStarted(0);
|
|
|
|
$trueCrimeEpisodeActionEntity->setTotal(123);
|
|
|
|
$trueCrimeEpisodeActionEntity->setTimestamp("2021-10-22T12:00:00");
|
|
|
|
$trueCrimeEpisodeActionEntity->setUserId(self::ADMIN);
|
|
|
|
$trueCrimeEpisodeActionEntity->setGuid(uniqid("self::TEST_GUID_1234"));
|
|
|
|
$this->episodeActionWriter->save($trueCrimeEpisodeActionEntity);
|
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
$episodeActionBeforeConversion = $this->episodeActionMapper->findByGuid(
|
2021-10-13 17:59:31 +00:00
|
|
|
$scienceEpisodeActionEntity->getGuid(),
|
|
|
|
self::ADMIN
|
|
|
|
);
|
|
|
|
|
2021-10-05 10:30:52 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
2021-10-05 18:45:06 +00:00
|
|
|
$episodeActionBeforeConversion->getTimestampEpoch()
|
2021-10-05 10:30:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$timestampMigration = new TimestampMigration($this->dbConnection, $this->migrationConfig);
|
2022-05-03 21:05:15 +00:00
|
|
|
$timestampMigration->run($this->createMock(SimpleOutput::class));
|
2021-10-05 10:30:52 +00:00
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
$scienceEpisodeActionAfterConversion = $this->episodeActionMapper->findByGuid(
|
2021-10-13 17:59:31 +00:00
|
|
|
$scienceEpisodeActionEntity->getGuid(),
|
|
|
|
self::ADMIN
|
|
|
|
);
|
2021-10-05 10:30:52 +00:00
|
|
|
$this->assertSame(
|
2021-10-05 18:45:06 +00:00
|
|
|
1629676736,
|
2021-10-13 17:59:31 +00:00
|
|
|
$scienceEpisodeActionAfterConversion->getTimestampEpoch()
|
|
|
|
);
|
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
$trueCrimeEpisodeActionAfterConversion = $this->episodeActionMapper->findByGuid(
|
2021-10-13 17:59:31 +00:00
|
|
|
$trueCrimeEpisodeActionEntity->getGuid(),
|
|
|
|
self::ADMIN
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
1634904000,
|
|
|
|
$trueCrimeEpisodeActionAfterConversion->getTimestampEpoch()
|
2021-10-05 10:30:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @after
|
|
|
|
*/
|
|
|
|
public function after()
|
|
|
|
{
|
2021-10-18 08:36:22 +00:00
|
|
|
$this->rollbackTransaction();
|
2021-10-05 10:30:52 +00:00
|
|
|
}
|
|
|
|
}
|