Skip to content

Commit

Permalink
Added tests for SystemLanguagesToServiceRector
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jan 26, 2024
1 parent 978fca9 commit 3d8b9ee
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Contao\Rector\Tests\Rector\SystemLanguagesToServiceRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class SystemLanguagesToServiceRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/config.php';
}
}
10 changes: 10 additions & 0 deletions tests/Rector/SystemLanguagesToServiceRector/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Contao\Rector\Rector\SystemLanguagesToServiceRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(SystemLanguagesToServiceRector::class);
};
21 changes: 21 additions & 0 deletions tests/Rector/SystemLanguagesToServiceRector/fixture/basic.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo
{
public function bar()
{
$languages = \Contao\System::getLanguages();
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$languages = \Contao\System::getContainer()->get('contao.intl.locales')->getLocales(null, true);
}
}
?>
35 changes: 35 additions & 0 deletions tests/Rector/SystemLanguagesToServiceRector/fixture/dca.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class Foo
{
public function bar()
{
$GLOBALS['TL_DCA']['tl_foo']['fields']['languages'] = [
'label' => &$GLOBALS['TL_LANG']['MSC']['geoip_countries'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => static fn () => \Contao\System::getLanguages(),
'eval' => ['includeBlankOption' => true, 'mandatory' => true, 'multiple' => true, 'chosen' => true, 'csv' => ',', 'tl_class' => 'w50',],
'sql' => ['type' => 'string', 'length' => 255, 'default' => ''],
];
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$GLOBALS['TL_DCA']['tl_foo']['fields']['languages'] = [
'label' => &$GLOBALS['TL_LANG']['MSC']['geoip_countries'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => static fn () => \Contao\System::getContainer()->get('contao.intl.locales')->getLocales(null, true),
'eval' => ['includeBlankOption' => true, 'mandatory' => true, 'multiple' => true, 'chosen' => true, 'csv' => ',', 'tl_class' => 'w50',],
'sql' => ['type' => 'string', 'length' => 255, 'default' => ''],
];
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo
{
public function bar()
{
$languages = \Contao\System::getLanguages(true);
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$languages = \Contao\System::getContainer()->get('contao.intl.locales')->getEnabledLocales(null, true);
}
}
?>

0 comments on commit 3d8b9ee

Please sign in to comment.