Applied rector to remaining test files

This commit is contained in:
Jan Böhmer 2024-06-22 00:37:47 +02:00
parent af325612aa
commit d898ca736c
5 changed files with 52 additions and 61 deletions

View file

@ -56,13 +56,11 @@ class APIDocsAvailabilityTest extends WebTestCase
self::assertResponseStatusCodeSame(403); self::assertResponseStatusCodeSame(403);
} }
public static function urlProvider(): array public static function urlProvider(): \Iterator
{ {
return [ yield ['/api'];
['/api'], yield ['/api/docs.html'];
['/api/docs.html'], yield ['/api/docs.json'];
['/api/docs.json'], yield ['/api/docs.jsonld'];
['/api/docs.jsonld'],
];
} }
} }

View file

@ -34,14 +34,12 @@ abstract class AbstractAdminControllerTest extends WebTestCase
protected static string $base_path = 'not_valid'; protected static string $base_path = 'not_valid';
protected static string $entity_class = 'not valid'; protected static string $entity_class = 'not valid';
public function readDataProvider(): array public function readDataProvider(): \Iterator
{ {
return [ yield ['noread', false];
['noread', false], yield ['anonymous', true];
['anonymous', true], yield ['user', true];
['user', true], yield ['admin', true];
['admin', true],
];
} }
/** /**
@ -98,14 +96,12 @@ abstract class AbstractAdminControllerTest extends WebTestCase
$this->assertSame($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!'); $this->assertSame($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!');
} }
public function deleteDataProvider(): array public function deleteDataProvider(): \Iterator
{ {
return [ yield ['noread', false];
['noread', false], yield ['anonymous', false];
['anonymous', false], yield ['user', true];
['user', true], yield ['admin', true];
['admin', true],
];
} }
/** /**

View file

@ -50,18 +50,16 @@ class RedirectControllerTest extends WebTestCase
$this->userRepo = $this->em->getRepository(User::class); $this->userRepo = $this->em->getRepository(User::class);
} }
public function urlMatchDataProvider(): array public function urlMatchDataProvider(): \Iterator
{ {
return [ yield ['/', true];
['/', true], yield ['/part/2/info', true];
['/part/2/info', true], yield ['/part/de/2', true];
['/part/de/2', true], yield ['/part/en/', true];
['/part/en/', true], yield ['/de/', false];
['/de/', false], yield ['/de_DE/', false];
['/de_DE/', false], yield ['/en/', false];
['/en/', false], yield ['/en_US/', false];
['/en_US/', false],
];
} }
/** /**
@ -81,22 +79,20 @@ class RedirectControllerTest extends WebTestCase
$this->assertSame($expect_redirect, $response->isRedirect()); $this->assertSame($expect_redirect, $response->isRedirect());
} }
public function urlAddLocaleDataProvider(): array public function urlAddLocaleDataProvider(): \Iterator
{ {
return [ //User locale, original target, redirect target
//User locale, original target, redirect target yield ['de', '/', '/de/'];
['de', '/', '/de/'], yield ['de', '/part/3', '/de/part/3'];
['de', '/part/3', '/de/part/3'], yield ['en', '/', '/en/'];
['en', '/', '/en/'], yield ['en', '/category/new', '/en/category/new'];
['en', '/category/new', '/en/category/new'], yield ['en_US', '/part/3', '/en_US/part/3'];
['en_US', '/part/3', '/en_US/part/3'], //Without an explicit set value, the user should be redirected to english version
//Without an explicit set value, the user should be redirected to english version yield [null, '/', '/en/'];
[null, '/', '/en/'], yield ['en_US', '/part/3', '/en_US/part/3'];
['en_US', '/part/3', '/en_US/part/3'], //Test that query parameters work
//Test that query parameters work yield ['de', '/dialog?target_id=133&target_type=part', '/de/dialog?target_id=133&target_type=part'];
['de', '/dialog?target_id=133&target_type=part', '/de/dialog?target_id=133&target_type=part'], yield ['en', '/dialog?storelocation=1', '/en/dialog?storelocation=1'];
['en', '/dialog?storelocation=1', '/en/dialog?storelocation=1'],
];
} }
/** /**

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/* /*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
namespace App\Tests\Controller; namespace App\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\KernelBrowser;
@ -49,4 +51,4 @@ class ScanControllerTest extends WebTestCase
$this->client->request('GET', '/scan/part/1'); $this->client->request('GET', '/scan/part/1');
$this->assertResponseRedirects('/en/part/1'); $this->assertResponseRedirects('/en/part/1');
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/* /*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
namespace App\Tests\Services\InfoProviderSystem\DTOs; namespace App\Tests\Services\InfoProviderSystem\DTOs;
use App\Services\InfoProviderSystem\DTOs\FileDTO; use App\Services\InfoProviderSystem\DTOs\FileDTO;
@ -27,18 +29,15 @@ class FileDTOTest extends TestCase
{ {
public static function escapingDataProvider(): array public static function escapingDataProvider(): \Iterator
{ {
return [ //Normal URLs must be unchanged, even if they contain special characters
//Normal URLs must be unchanged, even if they contain special characters yield ["https://localhost:8000/en/part/1335/edit#attachments", "https://localhost:8000/en/part/1335/edit#attachments"];
["https://localhost:8000/en/part/1335/edit#attachments", "https://localhost:8000/en/part/1335/edit#attachments"], yield ["https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()", "https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()"];
["https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()", "https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()"], //Remaining URL unsafe characters must be escaped
yield ["test%5Ese", "test^se"];
//Remaining URL unsafe characters must be escaped yield ["test%20se", "test se"];
["test%5Ese", "test^se"], yield ["test%7Cse", "test|se"];
["test%20se", "test se"],
["test%7Cse", "test|se"],
];
} }
/** /**