Skip to content

Commit be54290

Browse files
committed
Add IsSoundcloud display condition
1 parent 743aa69 commit be54290

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ayacoo\AyacooSoundcloud\Tca\DisplayCond;
6+
7+
class IsSoundcloud
8+
{
9+
/**
10+
* @param array<string,mixed> $parameters
11+
*/
12+
public function match(array $parameters): bool
13+
{
14+
$record = $parameters['record'] ?? [];
15+
if (!is_array($record)) {
16+
return false;
17+
}
18+
19+
return (!empty($record['soundcloud_html'] ?? ''));
20+
}
21+
}

Configuration/TCA/Overrides/sys_file_metadata.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'readOnly' => true,
1717
'size' => 40,
1818
],
19+
'displayCond' => 'USER:Ayacoo\\AyacooSoundcloud\\Tca\\DisplayCond\\IsSoundcloud->match',
1920
],
2021
'soundcloud_html' => [
2122
'exclude' => true,
@@ -27,6 +28,7 @@
2728
'rows' => 4,
2829
'readOnly' => true,
2930
],
31+
'displayCond' => 'USER:Ayacoo\\AyacooSoundcloud\\Tca\\DisplayCond\\IsSoundcloud->match',
3032
],
3133
'soundcloud_author_url' => [
3234
'exclude' => true,
@@ -38,6 +40,7 @@
3840
'readOnly' => true,
3941
'size' => 40,
4042
],
43+
'displayCond' => 'USER:Ayacoo\\AyacooSoundcloud\\Tca\\DisplayCond\\IsSoundcloud->match',
4144
],
4245
];
4346

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ayacoo\AyacooSoundcloud\Tests\Unit\Tca\DisplayCond;
6+
7+
use Ayacoo\AyacooSoundcloud\Tca\DisplayCond\IsSoundcloud;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class IsSoundcloudTest extends TestCase
11+
{
12+
private IsSoundcloud $subject;
13+
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
$this->subject = new IsSoundcloud();
18+
}
19+
20+
public function testReturnsFalseIfParametersAreEmpty(): void
21+
{
22+
self::assertFalse($this->subject->match([]));
23+
}
24+
25+
public function testReturnsFalseIfRecordIsNotArray(): void
26+
{
27+
$params = ['record' => 'not-an-array'];
28+
self::assertFalse($this->subject->match($params));
29+
}
30+
31+
public function testReturnsFalseIfSoundcloudHtmlIsMissing(): void
32+
{
33+
$params = ['record' => []];
34+
self::assertFalse($this->subject->match($params));
35+
}
36+
37+
public function testReturnsFalseIfSoundcloudHtmlIsEmptyString(): void
38+
{
39+
$params = ['record' => ['soundcloud_html' => '']];
40+
self::assertFalse($this->subject->match($params));
41+
}
42+
43+
public function testReturnsTrueIfSoundcloudHtmlHasContent(): void
44+
{
45+
$params = ['record' => ['soundcloud_html' => '<iframe>...</iframe>']];
46+
self::assertTrue($this->subject->match($params));
47+
}
48+
}

0 commit comments

Comments
 (0)