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\Log;
|
|
|
|
use OC\Migration\SimpleOutput;
|
2021-10-05 21:24:12 +00:00
|
|
|
use OC\OCS\Exception;
|
|
|
|
use OC\OCS\Result;
|
2021-10-05 10:30:52 +00:00
|
|
|
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\EpisodeActionRepository;
|
|
|
|
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;
|
|
|
|
use tests\Helper\Writer\TestWriter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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');
|
|
|
|
$this->container = $app->getContainer();
|
|
|
|
$this->episodeActionWriter = $this->container->get(EpisodeActionWriter::class);
|
2021-10-05 18:45:06 +00:00
|
|
|
$this->episodeActionMapper = $this->container->get(EpisodeActionMapper::class);
|
2021-10-05 10:30:52 +00:00
|
|
|
$this->dbConnection = $this->container->get(IDBConnection::class);
|
|
|
|
$this->migrationConfig = $this->container->get(AllConfig::class );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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-05 10:30:52 +00:00
|
|
|
$episodeActionEntity = new EpisodeActionEntity();
|
|
|
|
$episodeActionEntity->setPodcast("https://podcast_01.url");
|
|
|
|
$episodeActionEntity->setEpisode(uniqid("https://episode_01.url"));
|
|
|
|
$episodeActionEntity->setAction("PLAY");
|
|
|
|
$episodeActionEntity->setPosition(5);
|
|
|
|
$episodeActionEntity->setStarted(0);
|
|
|
|
$episodeActionEntity->setTotal(123);
|
2021-10-05 20:53:11 +00:00
|
|
|
$episodeActionEntity->setTimestamp("Sun Aug 22 23:58:56 GMT+00:00 2021");
|
2021-10-05 10:30:52 +00:00
|
|
|
$episodeActionEntity->setUserId(self::ADMIN);
|
|
|
|
$guid = uniqid("self::TEST_GUID_1234");
|
|
|
|
$episodeActionEntity->setGuid($guid);
|
|
|
|
$this->episodeActionWriter->save($episodeActionEntity);
|
|
|
|
|
2021-10-05 18:45:06 +00:00
|
|
|
$episodeActionBeforeConversion = $this->episodeActionMapper->findByEpisodeIdentifier($guid, 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);
|
|
|
|
$timestampMigration->run(new SimpleOutput(new Log(new TestWriter()), "gpoddersync"));
|
|
|
|
|
2021-10-05 18:45:06 +00:00
|
|
|
$episodeActionAfterConversion = $this->episodeActionMapper->findByEpisodeIdentifier($guid, self::ADMIN);
|
2021-10-05 10:30:52 +00:00
|
|
|
$this->assertSame(
|
2021-10-05 18:45:06 +00:00
|
|
|
1629676736,
|
|
|
|
$episodeActionAfterConversion->getTimestampEpoch()
|
2021-10-05 10:30:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @after
|
|
|
|
*/
|
|
|
|
public function after()
|
|
|
|
{
|
|
|
|
$this->rollbackTransation();
|
|
|
|
}
|
|
|
|
}
|