-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #647 from City-of-Helsinki/UHF-10406
UHF-10406: Improve helbit video handling
- Loading branch information
Showing
7 changed files
with
158 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
public/modules/custom/helfi_rekry_content/tests/src/Kernel/JobMigrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_rekry_content\Kernel; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\media\OEmbed\Provider; | ||
use Drupal\media\OEmbed\ProviderException; | ||
use Drupal\media\OEmbed\UrlResolverInterface; | ||
use Drupal\migrate\MigrateSkipRowException; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** | ||
* Job migration tests. | ||
*/ | ||
class JobMigrationTest extends KernelTestBase { | ||
|
||
use ProphecyTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'content_lock', | ||
'helfi_rekry_content', | ||
]; | ||
|
||
/** | ||
* Test video URL sanitization. | ||
* | ||
* @dataProvider videoUrlData | ||
*/ | ||
public function testVideoUrlSanitization(mixed $expected, array $videoUrls): void { | ||
foreach ($videoUrls as $videoUrl) { | ||
$this->assertEquals($expected, \_helfi_rekry_content_sanitize_video_url($videoUrl)); | ||
} | ||
} | ||
|
||
/** | ||
* Test video URL validation. | ||
*/ | ||
public function testVideoValidationExceptions(): void { | ||
$urlResolver = $this->prophesize(UrlResolverInterface::class); | ||
$urlResolver->getProviderByUrl(Argument::any()) | ||
->willThrow(ProviderException::class); | ||
|
||
$this->container->set(UrlResolverInterface::class, $urlResolver->reveal()); | ||
|
||
$this->expectException(MigrateSkipRowException::class); | ||
_helfi_rekry_content_get_video_url('some-url'); | ||
} | ||
|
||
/** | ||
* Test video URL validation with unknown provider. | ||
*/ | ||
public function testVideoValidationProvider(): void { | ||
$provider = new Provider('Some provider', 'https://example.com', [ | ||
['url' => 'https://example.com/oembed'], | ||
]); | ||
|
||
$urlResolver = $this->prophesize(UrlResolverInterface::class); | ||
$urlResolver->getProviderByUrl(Argument::any()) | ||
->willReturn($provider); | ||
|
||
$this->container->set(UrlResolverInterface::class, $urlResolver->reveal()); | ||
|
||
$this->expectException(MigrateSkipRowException::class); | ||
_helfi_rekry_content_get_video_url('some-url'); | ||
} | ||
|
||
/** | ||
* Data provider for testVideoUrlSanitization(). | ||
*/ | ||
public static function videoUrlData(): array { | ||
return [ | ||
['', [' ']], | ||
[ | ||
'https://www.youtube.com/watch?v=g2eYKMjE8ew', | ||
[ | ||
'youtube.com/watch?v=g2eYKMjE8ew', | ||
'youtu.be/g2eYKMjE8ew', | ||
'youtu.be/?v=g2eYKMjE8ew', | ||
'https://youtube.com/embed/g2eYKMjE8ew', | ||
'https://youtube.com/watch?v=g2eYKMjE8ew', | ||
'https://www.youtube.com/watch?v=g2eYKMjE8ew', | ||
'https://www.youtube.com/watch?foo=bar&v=g2eYKMjE8ew&bar=foo', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters