Skip to content

Commit

Permalink
Add AdminControllerTest to check form configurations and list configu…
Browse files Browse the repository at this point in the history
…rtions (#29)
  • Loading branch information
niklasnatter authored Oct 23, 2020
1 parent 49270bf commit 0643747
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/Functional/Controller/Admin/AdminControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace App\Tests\Functional\Controller\Admin;

use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\Finder\Finder;

class AdminControllerTest extends SuluTestCase
{
/**
* @var KernelBrowser
*/
private $client;

public function setUp(): void
{
$this->client = $this->createAuthenticatedClient();
}

/**
* @dataProvider loadFormKeys
*/
public function testFormMetadata(string $formKey): void
{
$this->client->request('GET', '/admin/metadata/form/' . $formKey);

$this->assertHttpStatusCode(200, $this->client->getResponse());
}

/**
* @dataProvider loadListKeys
*/
public function testListMetadata(string $listKey): void
{
$this->client->request('GET', '/admin/metadata/list/' . $listKey);

$this->assertHttpStatusCode(200, $this->client->getResponse());
}

public function testConfig(): void
{
$this->client->request('GET', '/admin/config');

$this->assertHttpStatusCode(200, $this->client->getResponse());
}

/**
* @return \Generator<array<string>>
*/
public function loadFormKeys()
{
return $this->getFileKeys('forms');
}

/**
* @return \Generator<array<string>>
*/
public function loadListKeys(): \Generator
{
return $this->getFileKeys('lists');
}

/**
* @return \Generator<array<string>>
*/
private function getFileKeys(string $type): \Generator
{
$finder = new Finder();
$path = __DIR__ . '/../../../../config/' . $type;

$path = realpath($path);
if (!$path) {
throw new \RuntimeException(sprintf('Could not find path: "%s"', $path));
}

$finder->in($path);

foreach ($finder as $file) {
yield [
$file->getFilenameWithoutExtension(),
];
}
}
}

0 comments on commit 0643747

Please sign in to comment.