Skip to content

Commit

Permalink
update functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Jul 26, 2020
1 parent 4e3f302 commit 4c9ce4e
Showing 1 changed file with 91 additions and 11 deletions.
102 changes: 91 additions & 11 deletions core-bundle/tests/Functional/Migration/RoutingMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Contao\CoreBundle\Tests\Functional\Migration;

use Contao\Config;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Migration\Version410\RoutingMigration;
use Contao\TestCase\FunctionalTestCase;
use Doctrine\DBAL\Connection;
Expand All @@ -33,30 +35,38 @@ public function testShouldRun(array $dropFields, bool $expected): void
$connection->exec('ALTER TABLE tl_page DROP '.$field);
}

$migration = new RoutingMigration($connection);
/** @var ContaoFramework $framework */
$framework = static::$container->get('contao.framework');

$migration = new RoutingMigration($connection, $framework);

$this->assertSame($expected, $migration->shouldRun());
}

public function shouldRunProvider(): \Generator
{
yield 'should not run if both fields exist' => [
yield 'should not run if all fields exist' => [
[],
false,
];

yield 'should not run if urlSuffix exist' => [
['urlPrefix'],
['urlPrefix', 'useFolderUrl'],
false,
];

yield 'should not run if urlPrefix exist' => [
['urlSuffix'],
['urlSuffix', 'useFolderUrl'],
false,
];

yield 'should run if both fields do not exist' => [
yield 'should not run if useFolderUrl exist' => [
['urlPrefix', 'urlSuffix'],
false,
];

yield 'should run if all fields do not exist' => [
['urlPrefix', 'urlSuffix', 'useFolderUrl'],
true,
];
}
Expand All @@ -68,14 +78,18 @@ public function testMigratesSchema(): void

/** @var Connection $connection */
$connection = static::$container->get('database_connection');
$connection->exec('ALTER TABLE tl_page DROP urlPrefix, DROP urlSuffix');
$connection->exec('ALTER TABLE tl_page DROP urlPrefix, DROP urlSuffix, DROP useFolderUrl');

$columns = $connection->getSchemaManager()->listTableColumns('tl_page');

$this->assertFalse(isset($columns['urlPrefix']));
$this->assertFalse(isset($columns['urlsuffix']));
$this->assertFalse(isset($columns['usefolderurl']));

/** @var ContaoFramework $framework */
$framework = static::$container->get('contao.framework');

$migration = new RoutingMigration($connection);
$migration = new RoutingMigration($connection, $framework);
$result = $migration->run();

$this->assertTrue($result->isSuccessful());
Expand All @@ -84,35 +98,45 @@ public function testMigratesSchema(): void

$this->assertTrue(isset($columns['urlprefix']));
$this->assertTrue(isset($columns['urlsuffix']));
$this->assertTrue(isset($columns['usefolderurl']));
}

/**
* @dataProvider migrationDataProvider
*/
public function testMigratesData(bool $prependLocale, string $urlSuffix): void
public function testMigratesData(bool $prependLocale, string $urlSuffix, bool $folderUrl): void
{
static::bootKernel();
static::resetDatabaseSchema();
static::loadFixtures([__DIR__.'/../../Fixtures/Functional/Migration/routing.yml'], false);

/** @var Connection $connection */
$connection = static::$container->get('database_connection');
$connection->exec('ALTER TABLE tl_page DROP urlPrefix, DROP urlSuffix');
$connection->exec('ALTER TABLE tl_page DROP urlPrefix, DROP urlSuffix, DROP useFolderUrl');

/** @var ContaoFramework $framework */
$framework = static::$container->get('contao.framework');

$migration = new RoutingMigration($connection, $urlSuffix, $prependLocale);
/** @var Config $config */
$config = $framework->getAdapter(Config::class);
$config->set('folderUrl', $folderUrl);

$migration = new RoutingMigration($connection, $framework, $urlSuffix, $prependLocale);
$migration->run();

$rows = $connection->fetchAll('SELECT type, language, urlPrefix, urlSuffix FROM tl_page');
$rows = $connection->fetchAll('SELECT type, language, urlPrefix, urlSuffix, useFolderUrl FROM tl_page');

foreach ($rows as $row) {
if ('root' !== $row['type']) {
$this->assertSame('', $row['urlPrefix']);
$this->assertSame('.html', $row['urlSuffix']);
$this->assertSame('', $row['useFolderUrl']);
continue;
}

$this->assertSame($prependLocale ? $row['language'] : '', $row['urlPrefix']);
$this->assertSame($urlSuffix, $row['urlSuffix']);
$this->assertSame($folderUrl ? '1' : '', $row['useFolderUrl']);
}
}

Expand All @@ -121,41 +145,97 @@ public function migrationDataProvider(): \Generator
yield [
false,
'.html',
true
];

yield [
true,
'.html',
true
];

yield [
false,
'.json',
true
];

yield [
true,
'.json',
true
];

yield [
false,
'/',
true
];

yield [
true,
'/',
true
];

yield [
false,
'',
true
];

yield [
true,
'',
true
];

yield [
false,
'.html',
true
];

yield [
true,
'.html',
false
];

yield [
false,
'.json',
false
];

yield [
true,
'.json',
false
];

yield [
false,
'/',
false
];

yield [
true,
'/',
false
];

yield [
false,
'',
false
];

yield [
true,
'',
false
];
}
}

0 comments on commit 4c9ce4e

Please sign in to comment.