View source
<?php
namespace Drupal\Tests\file_link\Functional;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\BrowserTestBase;
class FileLinkRedirectTest extends BrowserTestBase {
protected static $modules = [
'file_link',
'file_link_test',
'entity_test',
'link',
'field',
'user',
'system',
];
public function testRedirects($path, $size, $format) {
$entity = EntityTest::create([
'name' => 'Foo',
'type' => 'article',
]);
$entity
->set('url_without_extension', [
'uri' => Url::fromUri('base:' . $path, [
'absolute' => TRUE,
])
->toString(),
]);
$entity
->save();
$file_link = $entity
->get('url_without_extension')
->first();
$this
->assertEquals($size, $file_link
->getSize());
$this
->assertEquals($format, $file_link
->getFormat());
}
public function testNotValidRedirect() {
$entity = EntityTest::create([
'name' => 'Foo',
'type' => 'article',
]);
$entity
->set('url_without_extension', [
'uri' => Url::fromUri('base:/test/redirect/301/rst', [
'absolute' => TRUE,
])
->toString(),
]);
$violations = $entity
->get('url_without_extension')
->validate();
$this
->assertSame(1, $violations
->count());
}
public function redirectDataProvider() {
return [
[
'/test/redirect/301/md',
3,
'application/octet-stream',
],
[
'/test/redirect/302/md',
3,
'application/octet-stream',
],
];
}
}