Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sourcecode/hub/app/Http/Requests/OembedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Http\Requests;

use App\Oembed\OembedFormat;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

Expand All @@ -17,7 +16,7 @@ public function rules(): array
{
return [
'url' => ['required', 'url'],
'format' => ['sometimes', 'required', Rule::in(OembedFormat::values())],
'format' => ['sometimes', Rule::in(['json', 'xml'])],
];
}
}
5 changes: 0 additions & 5 deletions sourcecode/hub/app/Oembed/OembedFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ public function getContentType(): string
self::Xml => 'text/xml; charset=UTF-8',
};
}

public static function values(): array
{
return array_column(self::cases(), 'value');
}
}
27 changes: 1 addition & 26 deletions sourcecode/hub/tests/Feature/NdlaLegacy/OembedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

namespace Tests\Feature\NdlaLegacy;

use App\Http\Requests\OembedRequest;
use App\Models\Content;
use App\Models\ContentVersion;
use App\Oembed\OembedFormat;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Validator;
use Illuminate\Testing\Fluent\AssertableJson;
use PHPUnit\Framework\Attributes\TestWith;
use Tests\TestCase;
Expand Down Expand Up @@ -53,6 +50,7 @@ public function testOembed(string $endpoint): void
public function testCanPassLocale(): void
{
$id = $this->faker->uuid;

Content::factory()
->withVersion(ContentVersion::factory()->state([
'title' => 'My content',
Expand All @@ -76,27 +74,4 @@ public function testCanPassLocale(): void
)),
);
}

public function testFormatParameterValidation(): void
{
$request = new OembedRequest();
$rules = $request->rules();

// Only url parameter is required
$validator = Validator::make(['url' => $this->faker->url], $rules);
$this->assertTrue($validator->passes());

// Valid format parameter should pass validation
$validator = Validator::make(['url' => $this->faker->url, 'format' => OembedFormat::Xml->value], $rules);
$this->assertTrue($validator->passes());

// Empty format parameter should fail validation
$validator = Validator::make(['url' => $this->faker->url, 'format' => ''], $rules);
$this->assertTrue($validator->fails());

// Invalid format parameter should fail validation
$validator = Validator::make(['url' => $this->faker->url, 'format' => 'doc'], $rules);
$this->assertTrue($validator->fails());

}
}
Loading