Skip to content

Commit

Permalink
[TASK] Add quality pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ayacoo committed Mar 3, 2024
1 parent 1cce1d4 commit 468d52b
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Classes/Domain/Repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ayacoo\Tiktok\Domain\Repository;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
Expand All @@ -13,6 +14,8 @@ class FileRepository
{
private const SYS_FILE_TABLE = 'sys_file';

private ?AbstractPlatform $platform;

public function getVideosByFileExtension(string $extension, int $limit = 0): array
{
$queryBuilder = $this->getQueryBuilder(self::SYS_FILE_TABLE);
Expand All @@ -27,9 +30,15 @@ public function getVideosByFileExtension(string $extension, int $limit = 0): arr
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT)
);

$version = $this->platform->getName();
$randomFunction = match ($version) {
'mysql', 'pdo_mysql', 'drizzle_pdo_mysql' => 'RAND()',
default => 'random()',
};

$statement = $queryBuilder
->select('*')
->addSelectLiteral('RAND() AS randomnumber')
->addSelectLiteral($randomFunction . ' AS randomnumber')
->from(self::SYS_FILE_TABLE)
->where(...$whereConstraints)
->orderBy('randomnumber');
Expand All @@ -41,15 +50,13 @@ public function getVideosByFileExtension(string $extension, int $limit = 0): arr
return $queryBuilder->executeQuery()->fetchAllAssociative();
}

/**
* @param string $tableName
* @return QueryBuilder
*/
protected function getQueryBuilder(string $tableName = ''): QueryBuilder
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$connection = $connectionPool->getConnectionForTable($tableName);

$this->platform = $connection->getDatabasePlatform();

return $connection->createQueryBuilder();
}
}
66 changes: 66 additions & 0 deletions Tests/Functional/Domain/Repository/FileRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Ayacoo\Tiktok\Tests\Functional\Domain\Repository;

use Ayacoo\Tiktok\Domain\Repository\FileRepository;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class FileRepositoryTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['tiktok'];

private FileRepository $subject;

protected function setUp(): void
{
parent::setUp();

$this->subject = $this->get(FileRepository::class);
}

/**
* @test
*/
public function getVideosByFileExtensionForNoRecordsReturnsEmptyResult(): void
{
$result = $this->subject->getVideosByFileExtension('jpg', 10);

self::assertCount(0, $result);
}

/**
* @test
*/
public function getVideosByFileExtensionReturnsSoundcloudMedia(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/Basic.csv');
$row = $this->subject->getVideosByFileExtension('tiktok', 10);

self::assertCount(1, $row);
self::assertSame(1, $row[0]['uid']);
}

/**
* @test
*/
public function getVideosByFileExtensionWithMaxResultsReturnsSoundcloudMedia(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/MaxResults.csv');
$row = $this->subject->getVideosByFileExtension('tiktok', 1);

self::assertCount(1, $row);
}

/**
* @test
*/
public function getVideosByFileExtensionIgnoresMissingMedia(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/MissingTiktok.csv');
$row = $this->subject->getVideosByFileExtension('tiktok', 1);

self::assertCount(0, $row);
}
}
4 changes: 4 additions & 0 deletions Tests/Functional/Domain/Repository/Fixtures/Basic.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"sys_file"
,"uid","identifier","missing","extension"
,1,"/tiktok/armin_van_buuren_feat._mr_probz_-_another_you__out_now__by_armin_van_buuren.tiktok","0","tiktok"
,2,"/dummy/test.png","0","png"
4 changes: 4 additions & 0 deletions Tests/Functional/Domain/Repository/Fixtures/MaxResults.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"sys_file"
,"uid","identifier","missing","extension"
,1,"/tiktok/armin_van_buuren_feat._mr_probz_-_another_you__out_now__by_armin_van_buuren.soundcloud","0","tiktok"
,2,"/tiktok/scantraxx_-_back_to_the_rootz_002___hardstyle_classics_mix_by_scantraxx.tiktok","0","tiktok"
3 changes: 3 additions & 0 deletions Tests/Functional/Domain/Repository/Fixtures/MissingTiktok.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"sys_file"
,"uid","identifier","missing","extension"
,1,"/tiktok/armin_van_buuren_feat._mr_probz_-_another_you__out_now__by_armin_van_buuren.tiktok","1","tiktok"
32 changes: 32 additions & 0 deletions Tests/Unit/Helper/TiktokHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Ayacoo\Tiktok\Tests\Unit\Helper;

use Ayacoo\Tiktok\Helper\TiktokHelper;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

final class TiktokHelperTest extends UnitTestCase
{
private const TIKTOK_URL = 'https://www.tiktok.com/';

private TiktokHelper $subject;

protected function setUp(): void
{
parent::setUp();

$this->subject = new TiktokHelper('tiktok');
}

/**
* @test
*/
public function isAbstractOEmbedHelper(): void
{
self::assertInstanceOf(AbstractOEmbedHelper::class, $this->subject);
}
}

0 comments on commit 468d52b

Please sign in to comment.