-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for SystemLanguagesToServiceRector
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
tests/Rector/SystemLanguagesToServiceRector/SystemLanguagesToServiceRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
tests/Rector/SystemLanguagesToServiceRector/config/config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
tests/Rector/SystemLanguagesToServiceRector/fixture/basic.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
tests/Rector/SystemLanguagesToServiceRector/fixture/dca.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' => ''], | ||
]; | ||
} | ||
} | ||
?> |
21 changes: 21 additions & 0 deletions
21
tests/Rector/SystemLanguagesToServiceRector/fixture/installed_only.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
?> |