diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8d7c592b..7b7b8aaf 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -19,6 +19,7 @@ jobs: - '8.1' - '8.2' - '8.3' + - '8.4' steps: - name: Check out repository uses: actions/checkout@v4 @@ -57,10 +58,10 @@ jobs: - name: Run PHP linter (php-cs-fixer) run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer --diff --dry-run -v fix - - name: Atoum tests + - name: Unit tests run: | cp app/config/config.ini-ghactions app/config/config.ini - vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report + php ./vendor/bin/phpunit - name: Functional tests (API, pages) run: | diff --git a/.gitignore b/.gitignore index 7b2a47d7..83fb3e25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .php-cs-fixer.cache +.phpunit.result.cache *.pyc app/config/config.ini app/config/sources/*.json @@ -14,6 +15,7 @@ composer.phar logs/*.log logs/github_log.txt python-venv +tests/**/*.cache vendor web/data.tar.gz web/download/.htaccess diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8defb2b2..c74cd428 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -22,6 +22,10 @@ ], 'encoding' => true, 'full_opening_tag' => true, + 'method_argument_space' => [ + 'on_multiline' => 'ignore', + 'keep_multiple_spaces_after_comma' => false, + ], 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, diff --git a/app/classes/Transvision/Project.php b/app/classes/Transvision/Project.php index f69f6710..d02e134f 100644 --- a/app/classes/Transvision/Project.php +++ b/app/classes/Transvision/Project.php @@ -218,7 +218,7 @@ public static function getRepositoryLocales($repository, $ignored = []) $file_name = APP_SOURCES . "{$repository}.txt"; $supported_locales = []; if (file_exists($file_name)) { - $supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } // Make sure that the reference locale is included @@ -245,7 +245,7 @@ public static function getAllLocales() $file_name = APP_SOURCES . 'all_projects.txt'; $supported_locales = []; if (file_exists($file_name)) { - $supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } sort($supported_locales); diff --git a/app/classes/Transvision/Strings.php b/app/classes/Transvision/Strings.php index e97fd3ff..2a770a89 100644 --- a/app/classes/Transvision/Strings.php +++ b/app/classes/Transvision/Strings.php @@ -333,6 +333,6 @@ public static function levenshteinQuality($string1, $string2) mb_strlen($string2, 'UTF-8'), ]); - return (float) (1 - self::levenshteinUTF8($string1, $string2) / $length) * 100; + return (float) round((1 - self::levenshteinUTF8($string1, $string2) / $length) * 100, 5); } } diff --git a/app/classes/Transvision/TMX.php b/app/classes/Transvision/TMX.php index c1abe85e..07670ed6 100644 --- a/app/classes/Transvision/TMX.php +++ b/app/classes/Transvision/TMX.php @@ -13,19 +13,22 @@ class TMX /** * Generate a TMX file from a data source * - * @param array $strings All the strings the user picked - * @param string $target_lang Locale picked from which we get translations - * @param string $source_lang Source locale + * @param array $strings All the strings the user picked + * @param string $target_lang Locale picked from which we get translations + * @param string $source_lang Source locale + * @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used. * * @return mixed string that contains a TMX in xml format, False otherwise */ - public static function create($strings, $target_lang, $source_lang) + public static function create($strings, $target_lang, $source_lang, $time = null) { if ($strings[$target_lang] && $strings[$source_lang]) { + $creationDate = $time ?? date('c'); + $content = '' . "\n" . '' . "\n" . '
' . "\n" . '
' . "\n" . '' . "\n"; @@ -56,21 +59,24 @@ public static function create($strings, $target_lang, $source_lang) /** * Generate a TMX file from a data source with the format of OmegaT * - * @param array $strings All the strings the user picked - * @param string $target_lang Locale picked from which we get translations - * @param string $source_lang Source locale + * @param array $strings All the strings the user picked + * @param string $target_lang Locale picked from which we get translations + * @param string $source_lang Source locale + * @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used. * * @return mixed string that contains a TMX in xml format, False otherwise */ - public static function createOmegat($strings, $target_lang, $source_lang) + public static function createOmegat($strings, $target_lang, $source_lang, $time = null) { if ($strings[$target_lang] && $strings[$source_lang]) { + $creationDate = $time ?? date('c'); + $content = '' . "\n" . '' . "\n" . '' . "\n" . '
' + . ' creationdate="' . $creationDate . '" srclang="' . $source_lang . '">' . '
' . "\n" . '' . "\n"; diff --git a/app/inc/constants.php b/app/inc/constants.php index 6112de67..a10f179a 100644 --- a/app/inc/constants.php +++ b/app/inc/constants.php @@ -1,24 +1,24 @@ Bash for installation scripts and cron jobs
  • Python for extracting strings (compare-locales)
  • Composer, a dependency manager for PHP projects
  • -
  • Atoum, a unit testing framework for PHP
  • +
  • PHPUnit, a unit testing framework for PHP
  • jQuery, a JavaScript library
  • diff --git a/composer.json b/composer.json index 815ac336..7636dbf7 100644 --- a/composer.json +++ b/composer.json @@ -32,10 +32,10 @@ }, "require-dev": { - "atoum/atoum" : "~4.2", "symfony/var-dumper": "~6.4", - "friendsofphp/php-cs-fixer": "~3.64", - "pchevrel/verif": "0.4" + "friendsofphp/php-cs-fixer": "~3.75", + "pchevrel/verif": "0.4", + "phpunit/phpunit": "^10 || ^12" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..b4217280 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + + + + + + + tests/units + + + diff --git a/start.sh b/start.sh index 509a8938..531e40a4 100755 --- a/start.sh +++ b/start.sh @@ -57,7 +57,7 @@ case "$1" in SERVER="0.0.0.0:8082" ;; -tests) - php ./vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report + php ./vendor/bin/phpunit php ./tests/functional/api.php php ./tests/functional/pages.php vendor/bin/php-cs-fixer --diff --dry-run -v fix diff --git a/tests/functional/includes/init.php b/tests/functional/includes/init.php index d42478a0..157e01e4 100644 --- a/tests/functional/includes/init.php +++ b/tests/functional/includes/init.php @@ -1,6 +1,6 @@ assert - ->string($obj->getDefaultLocale()) - ->isEqualTo('en-US'); - } -} diff --git a/tests/units/Transvision/API.php b/tests/units/Transvision/APITest.php similarity index 79% rename from tests/units/Transvision/API.php rename to tests/units/Transvision/APITest.php index 8b44c579..5b32ec27 100644 --- a/tests/units/Transvision/API.php +++ b/tests/units/Transvision/APITest.php @@ -1,14 +1,15 @@ array($obj->getParameters($url['path'])) - ->isEqualTo($b); + ->assertSame($obj->getParameters($url['path']), $b); } - public function getExtraParametersDP() + public static function getExtraParametersDP() { return [ [ @@ -55,7 +53,7 @@ public function getExtraParametersDP() ], [ 'http://foobar.com/api/v1/tm/gecko_strings/en-US/fr/Bookmark/?foo=&bar=10', - ['foo' => '', 'bar' => 10], + ['foo' => '', 'bar' => '10'], ], [ 'http://foobar.com/api/v1/tm/gecko_strings/en-US/fr/Bookmark/?foo=bar&foo2=bar2', @@ -64,19 +62,16 @@ public function getExtraParametersDP() ]; } - /** - * @dataProvider getExtraParametersDP - */ + #[DataProvider('getExtraParametersDP')] public function testGetExtraParameters($a, $b) { $url = parse_url($a); - $obj = new _API($url); + $obj = new API($url); $this - ->array($obj->getExtraParameters($url['query'])) - ->isEqualTo($b); + ->assertSame($obj->getExtraParameters($url['query']), $b); } - public function isValidRequestDP() + public static function isValidRequestDP() { return [ // General @@ -126,44 +121,38 @@ public function isValidRequestDP() ]; } - /** - * @dataProvider isValidRequestDP - */ + #[DataProvider('isValidRequestDP')] public function testIsValidRequest($a, $b) { $url = parse_url($a); - $obj = new _API($url); - $obj->logging = false; // Logging interfers with Atoum + $obj = new API($url); + $obj->logging = false; // Logging interferes with tests $this - ->boolean($obj->isValidRequest()) - ->isEqualTo($b); + ->assertSame($obj->isValidRequest(), $b); } - public function getServiceDP() + public static function getServiceDP() { return [ ['http://foobar/api/v1/', 'Invalid service'], ['http://foobar/api/v1/wrong_service/gecko_strings/en-US/fr/hello world', 'Invalid service'], - ['http://foobar/api/wrong_version/tm/gecko_strings/en-US/fr/Bookmark/', true], - ['http://foobar/api/v1/entity/gecko_strings/?id=myid', true], - ['http://foobar/api/v1/locales/', true], - ['http://foobar/api/v1/search/strings/gecko_strings/en-US/fr/Add%20%20Bookmarks/', true], - ['http://foobar/api/v1/suggestions/beta/en-US/it/', true], - ['http://foobar/api/v1/tm/gecko_strings/en-US/fr/', true], - ['http://foobar/api/versions/', true], + ['http://foobar/api/wrong_version/tm/gecko_strings/en-US/fr/Bookmark/', 'tm'], + ['http://foobar/api/v1/entity/gecko_strings/?id=myid', 'entity'], + ['http://foobar/api/v1/locales/', 'locales'], + ['http://foobar/api/v1/search/strings/gecko_strings/en-US/fr/Add%20%20Bookmarks/', 'search'], + ['http://foobar/api/v1/suggestions/beta/en-US/it/', 'suggestions'], + ['http://foobar/api/v1/tm/gecko_strings/en-US/fr/', 'tm'], + ['http://foobar/api/versions/', 'versions'], ]; } - /** - * @dataProvider getServiceDP - */ + #[DataProvider('getServiceDP')] public function testGetService($a, $b) { $url = parse_url($a); - $obj = new _API($url); - $obj->logging = false; // Logging interfers with Atoum + $obj = new API($url); + $obj->logging = false; // Logging interferes with tests $this - ->variable($obj->getService()) - ->isEqualTo($b); + ->assertSame($obj->getService(), $b); } } diff --git a/tests/units/Transvision/AnalyseStrings.php b/tests/units/Transvision/AnalyzeStringsTest.php similarity index 95% rename from tests/units/Transvision/AnalyseStrings.php rename to tests/units/Transvision/AnalyzeStringsTest.php index 59e3eed4..a50c3e27 100644 --- a/tests/units/Transvision/AnalyseStrings.php +++ b/tests/units/Transvision/AnalyzeStringsTest.php @@ -1,14 +1,15 @@ string($obj->cleanUpEntities($a)) - ->isEqualTo($b); + ->assertSame($obj->cleanUpEntities($a), $b); } - public function differencesDP() + public static function differencesDP() { return [ [ @@ -310,14 +308,11 @@ public function differencesDP() ]; } - /** - * @dataProvider differencesDP - */ + #[DataProvider('differencesDP')] public function testDifferences($a, $b, $c, $d, $e) { - $obj = new _AnalyseStrings(); + $obj = new AnalyseStrings(); $this - ->array($obj->differences($a, $b, $c, $d)) - ->isEqualTo($e); + ->assertEqualsCanonicalizing($obj->differences($a, $b, $c, $d), $e); } } diff --git a/tests/units/Transvision/Bugzilla.php b/tests/units/Transvision/BugzillaTest.php similarity index 90% rename from tests/units/Transvision/Bugzilla.php rename to tests/units/Transvision/BugzillaTest.php index cf4aa13e..5f5d7c6a 100644 --- a/tests/units/Transvision/Bugzilla.php +++ b/tests/units/Transvision/BugzillaTest.php @@ -1,17 +1,21 @@ string($obj->reportErrorLink($a, $b, $c, $d, $e, $f)) - ->isEqualTo($g); + $obj = new ModifiedBugzilla(); + $result = $obj->reportErrorLink($a, $b, $c, $d, $e, $f); + $this->assertSame($g, $result); } } diff --git a/tests/units/Transvision/ChooseLocaleTest.php b/tests/units/Transvision/ChooseLocaleTest.php new file mode 100644 index 00000000..0360f556 --- /dev/null +++ b/tests/units/Transvision/ChooseLocaleTest.php @@ -0,0 +1,14 @@ +assertSame($obj->getDefaultLocale(), 'en-US'); + } +} diff --git a/tests/units/Transvision/Consistency.php b/tests/units/Transvision/ConsistencyTest.php similarity index 89% rename from tests/units/Transvision/Consistency.php rename to tests/units/Transvision/ConsistencyTest.php index 27d8b6f1..e6017b96 100644 --- a/tests/units/Transvision/Consistency.php +++ b/tests/units/Transvision/ConsistencyTest.php @@ -1,14 +1,15 @@ 'Les cookies', ], [ - 'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page', 'browser/pdfviewer/viewer.properties:last_page.title' => 'Aller à la Dernière page', - 'browser/chrome/browser/browser.properties:popupWarningButtonUnix' => 'Préférences', + 'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page', 'browser/chrome/browser/migration/migration.properties:1_safari' => 'Préférences', + 'browser/chrome/browser/browser.properties:popupWarningButtonUnix' => 'Préférences', ], ], ]; } - /** - * @dataProvider findDuplicates_DP - */ + #[DataProvider('findDuplicates_DP')] public function testFindDuplicatesID($a, $b) { - $obj = new _Consistency(); + $obj = new Consistency(); $this - ->array($obj->findDuplicates($a)) - ->isEqualTo($b); + ->assertEqualsCanonicalizing($obj->findDuplicates($a), $b); } - public function findDuplicatesSensitive_DP() + public static function findDuplicatesSensitive_DP() { return [ [ [ - 'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page', 'browser/pdfviewer/viewer.properties:last_page.title' => 'Aller à la Dernière page', + 'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page', 'browser/chrome/browser/migration/migration.properties:1_safari' => 'Préférences', 'devtools/shared/gclicommands.properties:cookieListDesc' => 'Afficher les cookies', 'browser/chrome/browser/browser.properties:popupWarningButtonUnix' => 'Préférences', 'browser/chrome/browser/aboutPrivateBrowsing.dtd:aboutPrivateBrowsing.info.cookies' => 'Les cookies', ], [ - 'browser/chrome/browser/browser.properties:popupWarningButtonUnix' => 'Préférences', 'browser/chrome/browser/migration/migration.properties:1_safari' => 'Préférences', + 'browser/chrome/browser/browser.properties:popupWarningButtonUnix' => 'Préférences', ], ], ]; } - /** - * @dataProvider findDuplicatesSensitive_DP - */ + #[DataProvider('findDuplicatesSensitive_DP')] public function testFindDuplicatesSensitiveID($a, $b) { - $obj = new _Consistency(); + $obj = new Consistency(); $this - ->array($obj->findDuplicates($a, False)) - ->isEqualTo($b); + ->assertEqualsCanonicalizing($obj->findDuplicates($a, False), $b); } - public function filterStrings_DP() + public static function filterStrings_DP() { return [ [ @@ -96,26 +91,23 @@ public function filterStrings_DP() [ 'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page', 'browser/chrome/browser/aboutPrivateBrowsing.dtd:aboutPrivateBrowsing.info.cookies' => 'Les cookies', - 'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours', 'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer', + 'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours', 'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments', ], ], ]; } - /** - * @dataProvider filterStrings_DP - */ + #[DataProvider('filterStrings_DP')] public function testFilterStrings($a, $b, $c) { - $obj = new _Consistency(); + $obj = new Consistency(); $this - ->array($obj->filterStrings($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->filterStrings($a, $b), $c); } - public function filterComponents_DP() + public static function filterComponents_DP() { return [ [ @@ -159,14 +151,11 @@ public function filterComponents_DP() ]; } - /** - * @dataProvider filterComponents_DP - */ + #[DataProvider('filterComponents_DP')] public function testFilterComponents($a, $b, $c) { - $obj = new _Consistency(); + $obj = new Consistency(); $this - ->array($obj->filterComponents($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->filterComponents($a, $b), $c); } } diff --git a/tests/units/Transvision/Dotlang.php b/tests/units/Transvision/DotlangTest.php similarity index 68% rename from tests/units/Transvision/Dotlang.php rename to tests/units/Transvision/DotlangTest.php index 2fd3fe35..30b3ffac 100644 --- a/tests/units/Transvision/Dotlang.php +++ b/tests/units/Transvision/DotlangTest.php @@ -1,14 +1,15 @@ array($obj->getLangFilesList($a)) - ->isEqualTo($b) + ->assertSame($obj->getLangFilesList($a), $b) ; } - public function getFileDP() + public static function getFileDP() { return [ [ @@ -55,18 +53,15 @@ public function getFileDP() ]; } - /** - * @dataProvider getFileDP - */ + #[DataProvider('getFileDP')] public function testGetFile($a, $b) { - $obj = new _Dotlang(); + $obj = new Dotlang(); $this - ->array($obj->getFile($a)) - ->isEqualTo($b); + ->assertSame($obj->getFile($a), $b); } - public function getStringsDP() + public static function getStringsDP() { return [ [ @@ -92,32 +87,26 @@ public function getStringsDP() ]; } - /** - * @dataProvider getStringsDP - */ + #[DataProvider('getStringsDP')] public function testGetStrings($a, $b, $c) { - $obj = new _Dotlang(); + $obj = new Dotlang(); $this - ->array($obj->getStrings($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->getStrings($a, $b), $c); } - public function generateStringID_DP() + public static function generateStringID_DP() { return [ ['mozilla_org/main.lang', 'Back to home page', 'mozilla_org/main.lang:a922fff6646b0eb4db05fe6e0894af7d'], ]; } - /** - * @dataProvider generateStringID_DP - */ + #[DataProvider('generateStringID_DP')] public function testGenerateStringID($a, $b, $c) { - $obj = new _Dotlang(); + $obj = new Dotlang(); $this - ->string($obj->generateStringID($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->generateStringID($a, $b), $c); } } diff --git a/tests/units/Transvision/Po.php b/tests/units/Transvision/Po.php deleted file mode 100644 index a4966004..00000000 --- a/tests/units/Transvision/Po.php +++ /dev/null @@ -1,95 +0,0 @@ -getStrings(TEST_FILES . 'po/it_app.po', 'focus_android'); - - // Check total number of strings - $this - ->integer(count($strings)) - ->isEqualTo(17); - - // Check strings - $this - ->string($strings['focus_android/it_app.po:3071c8a7530990a564b943a69f4ac652']) - ->isEqualTo('Cerca o inserisci un indirizzo'); - - $this - ->string($strings['focus_android/it_app.po:0d6ef5cb439f059884232d5680ac138f']) - ->isEqualTo('Elementi traccianti bloccati'); - - // Test plurals - $strings = $obj->getStrings(TEST_FILES . 'po/ga_app.po', 'focus_android'); - - // Check total number of strings - $this - ->integer(count($strings)) - ->isEqualTo(2); - - // Check strings - $this - ->string($strings['focus_android/ga_app.po:b8c8fe8a54683f91f8ed8a54d7f76dec']) - ->isEqualTo('Thug {0} agus duine amháin eile freagra air'); - - $this - ->string($strings['focus_android/ga_app.po:1626bdedbed9939897d17cdeb4fe5e84']) - ->isEqualTo("Thug {0} agus {1} dhuine eile freagra air\nThug {0} agus {1} dhuine eile freagra air\nThug {0} agus {1} nduine eile freagra air\nThug {0} agus {1} duine eile freagra air"); - - // Test .pot file - $strings = $obj->getStrings(TEST_FILES . 'po/app.pot', 'focus_android', true); - - // Check total number of strings - $this - ->integer(count($strings)) - ->isEqualTo(16); - - // Check strings - $this - ->string($strings['focus_android/app.po:5ad79e8b3a9423d5a964bd6cc2e87000']) - ->isEqualTo('About'); - - $this - ->string($strings['focus_android/app.po:ebd82695e1086e20fd85d3532397b30f']) - ->isEqualTo('Open with %1$s'); - } - - public function generateStringID_DP() - { - return [ - [ - 'focus_android', - 'app.po', - 'Add to Home screen', - 'focus_android/app.po:1dafea7725862ca854c408f0e2df9c88', - ], - [ - 'focus_android', - 'app.po', - 'Your browsing history has been erased.', - 'focus_android/app.po:e62a7bce66ff3ed794cf9fb19081a066', - ], - ]; - } - - /** - * @dataProvider generateStringID_DP - */ - public function testGenerateStringID($a, $b, $c, $d) - { - $obj = new _Po(); - $this - ->string($obj->generateStringID($a, $b, $c)) - ->isEqualTo($d); - } -} diff --git a/tests/units/Transvision/PoTest.php b/tests/units/Transvision/PoTest.php new file mode 100644 index 00000000..77f725e1 --- /dev/null +++ b/tests/units/Transvision/PoTest.php @@ -0,0 +1,84 @@ +getStrings(TEST_FILES . 'po/it_app.po', 'focus_android'); + + // Check total number of strings + $this + ->assertCount(17, $strings); + + // Check strings + $this + ->assertSame($strings['focus_android/it_app.po:3071c8a7530990a564b943a69f4ac652'], 'Cerca o inserisci un indirizzo'); + + $this + ->assertSame($strings['focus_android/it_app.po:0d6ef5cb439f059884232d5680ac138f'], 'Elementi traccianti bloccati'); + + // Test plurals + $strings = $obj->getStrings(TEST_FILES . 'po/ga_app.po', 'focus_android'); + + // Check total number of strings + $this + ->assertCount(2, $strings); + + // Check strings + $this + ->assertSame($strings['focus_android/ga_app.po:b8c8fe8a54683f91f8ed8a54d7f76dec'], 'Thug {0} agus duine amháin eile freagra air'); + + $this + ->assertSame($strings['focus_android/ga_app.po:1626bdedbed9939897d17cdeb4fe5e84'], "Thug {0} agus {1} dhuine eile freagra air\nThug {0} agus {1} dhuine eile freagra air\nThug {0} agus {1} nduine eile freagra air\nThug {0} agus {1} duine eile freagra air"); + + // Test .pot file + $strings = $obj->getStrings(TEST_FILES . 'po/app.pot', 'focus_android', true); + + // Check total number of strings + $this + ->assertCount(16, $strings); + + // Check strings + $this + ->assertSame($strings['focus_android/app.po:5ad79e8b3a9423d5a964bd6cc2e87000'], 'About'); + + $this + ->assertSame($strings['focus_android/app.po:ebd82695e1086e20fd85d3532397b30f'], 'Open with %1$s'); + } + + public static function generateStringID_DP() + { + return [ + [ + 'focus_android', + 'app.po', + 'Add to Home screen', + 'focus_android/app.po:1dafea7725862ca854c408f0e2df9c88', + ], + [ + 'focus_android', + 'app.po', + 'Your browsing history has been erased.', + 'focus_android/app.po:e62a7bce66ff3ed794cf9fb19081a066', + ], + ]; + } + + #[DataProvider('generateStringID_DP')] + public function testGenerateStringID($a, $b, $c, $d) + { + $obj = new Po(); + $this + ->assertSame($obj->generateStringID($a, $b, $c), $d); + } +} diff --git a/tests/units/Transvision/Project.php b/tests/units/Transvision/Project.php deleted file mode 100644 index 1ca7d5ed..00000000 --- a/tests/units/Transvision/Project.php +++ /dev/null @@ -1,238 +0,0 @@ -array($obj->getRepositories(true)) - ->isEqualTo($repos); - - $repos = ['all_projects', 'gecko_strings', 'mozilla_org']; - $this - ->array($obj->getRepositories()) - ->isEqualTo($repos); - } - - public function testMetaRepository() - { - $obj = new _Project(); - $this - ->boolean($obj->isMetaRepository('all_projects')) - ->isEqualTo(true); - $this - ->boolean($obj->isMetaRepository('gecko_strings')) - ->isEqualTo(false); - $this - ->string($obj->getMetaRepository()) - ->isEqualTo('all_projects'); - } - - public function testIsReferenceLocale() - { - $obj = new _Project(); - $this - ->boolean($obj->isReferenceLocale('en-US', 'all_projects')) - ->isEqualTo(true); - $this - ->boolean($obj->isReferenceLocale('en', 'mozilla_org')) - ->isEqualTo(true); - $this - ->boolean($obj->isReferenceLocale('fr', 'mozilla_org')) - ->isEqualTo(false); - } - - public function testGetRepositoriesNames() - { - $obj = new _Project(); - $repos = [ - 'gecko_strings' => 'Gecko Products', - 'mozilla_org' => 'mozilla.org', - ]; - $this - ->array($obj->getRepositoriesNames(true)) - ->isEqualTo($repos); - - $repos = [ - 'all_projects' => 'All Projects', - 'gecko_strings' => 'Gecko Products', - 'mozilla_org' => 'mozilla.org', - ]; - $this - ->array($obj->getRepositoriesNames()) - ->isEqualTo($repos); - } - - public function testGetDesktopRepositories() - { - $obj = new _Project(); - $repos = ['gecko_strings', 'seamonkey', 'thunderbird']; - $this - ->array($obj->getDesktopRepositories()) - ->isEqualTo($repos); - } - - public function isDesktopRepositoryDP() - { - return [ - ['gecko_strings', true], - ['firefox_ios', false], - ['mozilla_org', false], - ['randomrepo', false], - ]; - } - - /** - * @dataProvider isDesktopRepositoryDP - */ - public function testIsDesktopRepository($a, $b) - { - $obj = new _Project(); - $this - ->boolean($obj->isDesktopRepository($a)) - ->isEqualTo($b); - } - - public function getRepositoryLocalesDP() - { - return [ - ['gecko_strings', ['en-US', 'fr', 'it'], []], - ['gecko_strings', ['fr', 'it'], ['en-US']], - ['gecko_strings', ['it'], ['en-US', 'fr']], - ]; - } - - /** - * @dataProvider getRepositoryLocalesDP - */ - public function testGetRepositoryLocales($a, $b, $c) - { - $obj = new _Project(); - $this - ->array($obj->getRepositoryLocales($a, $b)) - ->isEqualTo($c); - } - - public function getLocaleRepositoriesDP() - { - return [ - ['fr', ['gecko_strings', 'mozilla_org']], - ['foobar', []], - ]; - } - - /** - * @dataProvider getLocaleRepositoriesDP - */ - public function testGetLocaleRepositories($a, $b) - { - $obj = new _Project(); - $this - ->array($obj->getLocaleRepositories($a)) - ->isEqualTo($b); - } - - public function testGetReferenceLocale() - { - $obj = new _Project(); - $this - ->string($obj->getReferenceLocale('gecko_strings')) - ->isEqualTo('en-US'); - $this - ->string($obj->getReferenceLocale('mozilla_org')) - ->isEqualTo('en'); - } - - public function testIstReferenceLocale() - { - $obj = new _Project(); - $this - ->boolean($obj->isReferenceLocale('en-US', 'gecko_strings')) - ->isEqualTo(True); - $this - ->boolean($obj->isReferenceLocale('en', 'gecko_strings')) - ->isEqualTo(False); - $this - ->boolean($obj->isReferenceLocale('en', 'mozilla_org')) - ->isEqualTo(True); - } - - public function testGetAllLocales() - { - $obj = new _Project(); - $this - ->array($obj->getAllLocales()) - ->isEqualTo(['en-US', 'fr', 'it']); - } - - public function testIsValidRepository() - { - $obj = new _Project(); - $this - ->boolean($obj->isValidRepository('gecko_strings')) - ->isEqualTo(true); - $this - ->boolean($obj->isValidRepository('foo')) - ->isEqualTo(false); - } - - public function getLocaleInContextDP() - { - return [ - ['fr', 'bugzilla', 'fr'], - ['es', 'bugzilla', 'es-ES'], - ['pa', 'bugzilla', 'pa-IN'], - ['gu', 'bugzilla', 'gu-IN'], - ['sr', 'bugzilla', 'sr'], - ['sr-Cyrl', 'bugzilla', 'sr'], - ['sr-Latn', 'bugzilla', 'sr'], - ['es', 'mozilla_org', 'es-ES'], - ['es-AR', 'mozilla_org', 'es-AR'], - ['sr-Cyrl', 'mozilla_org', 'sr'], - ['es-ES', 'foobar', 'es-ES'], - ['fr', 'foobar', 'fr'], - ['es-ES', 'firefox_ios', 'es'], - ['es', 'firefox_ios', 'es'], - ['son', 'firefox_ios', 'ses'], - ]; - } - - /** - * @dataProvider getLocaleInContextDP - */ - public function testGetLocaleInContext($a, $b, $c) - { - $obj = new _Project(); - $this - ->string($obj->getLocaleInContext($a, $b)) - ->isEqualTo($c); - } - - public function getLocaleToolDP() - { - return [ - ['fr', ''], - ['sr', 'pontoon'], - ['te', 'pontoon'], - ]; - } - - /** - * @dataProvider getLocaleToolDP - */ - public function testGetLocaleTool($a, $b) - { - $obj = new _Project(); - $this - ->string($obj->getLocaleTool($a)) - ->isEqualTo($b); - } -} diff --git a/tests/units/Transvision/ProjectTest.php b/tests/units/Transvision/ProjectTest.php new file mode 100644 index 00000000..d23bde79 --- /dev/null +++ b/tests/units/Transvision/ProjectTest.php @@ -0,0 +1,205 @@ +assertSame($obj->getRepositories(true), $repos); + + $repos = ['all_projects', 'gecko_strings', 'mozilla_org']; + $this + ->assertSame($obj->getRepositories(), $repos); + } + + public function testMetaRepository() + { + $obj = new Project(); + $this + ->assertSame($obj->isMetaRepository('all_projects'), true); + $this + ->assertSame($obj->isMetaRepository('gecko_strings'), false); + $this + ->assertSame($obj->getMetaRepository(), 'all_projects'); + } + + public function testIsReferenceLocale() + { + $obj = new Project(); + $this + ->assertSame($obj->isReferenceLocale('en-US', 'all_projects'), true); + $this + ->assertSame($obj->isReferenceLocale('en', 'mozilla_org'), true); + $this + ->assertSame($obj->isReferenceLocale('fr', 'mozilla_org'), false); + } + + public function testGetRepositoriesNames() + { + $obj = new Project(); + $repos = [ + 'gecko_strings' => 'Gecko Products', + 'mozilla_org' => 'mozilla.org', + ]; + $this + ->assertEqualsCanonicalizing($obj->getRepositoriesNames(true), $repos); + + $repos = [ + 'all_projects' => 'All Projects', + 'gecko_strings' => 'Gecko Products', + 'mozilla_org' => 'mozilla.org', + ]; + $this + ->assertEqualsCanonicalizing($obj->getRepositoriesNames(), $repos); + } + + public function testGetDesktopRepositories() + { + $obj = new Project(); + $repos = ['gecko_strings', 'seamonkey', 'thunderbird']; + $this + ->assertSame($obj->getDesktopRepositories(), $repos); + } + + public static function isDesktopRepositoryDP() + { + return [ + ['gecko_strings', true], + ['firefox_ios', false], + ['mozilla_org', false], + ['randomrepo', false], + ]; + } + + #[DataProvider('isDesktopRepositoryDP')] + public function testIsDesktopRepository($a, $b) + { + $obj = new Project(); + $this + ->assertSame($obj->isDesktopRepository($a), $b); + } + + public static function getRepositoryLocalesDP() + { + return [ + ['gecko_strings', ['en-US', 'fr', 'it'], []], + ['gecko_strings', ['fr', 'it'], ['en-US']], + ['gecko_strings', ['it'], ['en-US', 'fr']], + ]; + } + + #[DataProvider('getRepositoryLocalesDP')] + public function testGetRepositoryLocales($a, $b, $c) + { + $obj = new Project(); + $this + ->assertSame($obj->getRepositoryLocales($a, $b), $c); + } + + public static function getLocaleRepositoriesDP() + { + return [ + ['fr', ['gecko_strings', 'mozilla_org']], + ['foobar', []], + ]; + } + + #[DataProvider('getLocaleRepositoriesDP')] + public function testGetLocaleRepositories($a, $b) + { + $obj = new Project(); + $this + ->assertSame($obj->getLocaleRepositories($a), $b); + } + + public function testGetReferenceLocale() + { + $obj = new Project(); + $this + ->assertSame($obj->getReferenceLocale('gecko_strings'), 'en-US'); + $this + ->assertSame($obj->getReferenceLocale('mozilla_org'), 'en'); + } + + public function testIstReferenceLocale() + { + $obj = new Project(); + $this + ->assertSame($obj->isReferenceLocale('en-US', 'gecko_strings'), True); + $this + ->assertSame($obj->isReferenceLocale('en', 'gecko_strings'), False); + $this + ->assertSame($obj->isReferenceLocale('en', 'mozilla_org'), True); + } + + public function testGetAllLocales() + { + $obj = new Project(); + $this + ->assertSame($obj->getAllLocales(), ['en-US', 'fr', 'it']); + } + + public function testIsValidRepository() + { + $obj = new Project(); + $this + ->assertSame($obj->isValidRepository('gecko_strings'), true); + $this + ->assertSame($obj->isValidRepository('foo'), false); + } + + public static function getLocaleInContextDP() + { + return [ + ['fr', 'bugzilla', 'fr'], + ['es', 'bugzilla', 'es-ES'], + ['pa', 'bugzilla', 'pa-IN'], + ['gu', 'bugzilla', 'gu-IN'], + ['sr', 'bugzilla', 'sr'], + ['sr-Cyrl', 'bugzilla', 'sr'], + ['sr-Latn', 'bugzilla', 'sr'], + ['es', 'mozilla_org', 'es-ES'], + ['es-AR', 'mozilla_org', 'es-AR'], + ['sr-Cyrl', 'mozilla_org', 'sr'], + ['es-ES', 'foobar', 'es-ES'], + ['fr', 'foobar', 'fr'], + ['es-ES', 'firefox_ios', 'es'], + ['es', 'firefox_ios', 'es'], + ['son', 'firefox_ios', 'ses'], + ]; + } + + #[DataProvider('getLocaleInContextDP')] + public function testGetLocaleInContext($a, $b, $c) + { + $obj = new Project(); + $this + ->assertSame($obj->getLocaleInContext($a, $b), $c); + } + + public static function getLocaleToolDP() + { + return [ + ['fr', ''], + ['sr', 'pontoon'], + ['te', 'pontoon'], + ]; + } + + #[DataProvider('getLocaleToolDP')] + public function testGetLocaleTool($a, $b) + { + $obj = new Project(); + $this + ->assertSame($obj->getLocaleTool($a), $b); + } +} diff --git a/tests/units/Transvision/Search.php b/tests/units/Transvision/Search.php deleted file mode 100644 index 04b8a6e4..00000000 --- a/tests/units/Transvision/Search.php +++ /dev/null @@ -1,262 +0,0 @@ -string($obj->getSearchTerms()) - ->isEqualTo(''); - $this - ->string($obj->getRegex()) - ->isEqualTo(''); - $this - ->boolean($obj->isCaseSensitive()) - ->isEqualTo(false); - $this - ->boolean($obj->isEachWord()) - ->isEqualTo(false); - $this - ->boolean($obj->isEntireString()) - ->isEqualTo(false); - $this - ->string($obj->getRegexSearchTerms()) - ->isEqualTo(''); - $this - ->string($obj->getRepository()) - ->isEqualTo('gecko_strings'); - $this - ->string($obj->getSearchType()) - ->isEqualTo('strings'); - $this - ->string($obj->getLocale('source')) - ->isEqualTo(''); - $this - ->array($obj->getFormSearchOptions()) - ->isEqualTo( - [ - 'case_sensitive', 'entire_string', 'repo', - 'search_type', 'each_word', 'entire_words', - ]); - $this - ->array($obj->getFormCheckboxes()) - ->isEqualTo( - [ - 'case_sensitive', 'entire_string', - 'each_word', 'entire_words', - ]); - } - - public function testSetSearchTerms() - { - $obj = new _Search(); - $obj->setSearchTerms(' foobar '); - $this - ->string($obj->getSearchTerms()) - ->isEqualTo(' foobar '); - $this - ->string($obj->getRegexSearchTerms()) - ->isEqualTo(' foobar '); - } - - public function testSetRegexSearchTerms() - { - $obj = new _Search(); - $obj->setRegexSearchTerms('A new hope'); - $this - ->string($obj->getRegexSearchTerms()) - ->isEqualTo('A new hope') - ->string($obj->getRegex()) - ->isEqualTo('~A new hope~iu'); - } - - public function testSetRegexCaseInsensitive() - { - $obj = new _Search(); - - // Test strings (as passed from GET) - $obj->setRegexCaseInsensitive('sensitive'); - $this - ->string($obj->getRegex()) - ->isEqualTo('~~u'); - - $obj->setRegexCaseInsensitive(''); - $this - ->string($obj->getRegex()) - ->isEqualTo('~~iu'); - - // Test boolean values - $obj->setRegexCaseInsensitive(true); - $this - ->string($obj->getRegex()) - ->isEqualTo('~~u'); - - $obj->setRegexCaseInsensitive(false); - $this - ->string($obj->getRegex()) - ->isEqualTo('~~iu'); - } - - public function testSetRegexEntireWords() - { - $obj = new _Search(); - $obj->setRegexEntireWords('entire_words'); - - $this - ->boolean($obj->isEntireWords()) - ->isEqualTo(true) - ->string($obj->getRegex()) - ->isEqualTo('~\b\b~iu'); - - $obj->setRegexEntireWords(false); - $this - ->boolean($obj->isEntireWords()) - ->isEqualTo(false) - ->string($obj->getRegex()) - ->isEqualTo('~~iu'); - } - - public function testSetRegexEntireString() - { - $obj = new _Search(); - $obj->setRegexEntireString('entire_string'); - $this - ->boolean($obj->isEntireString()) - ->isEqualTo(true) - ->string($obj->getRegex()) - ->isEqualTo('~^$~iu'); - - $obj->setRegexEntireString(false); - $this - ->boolean($obj->isEntireString()) - ->isEqualTo(false) - ->string($obj->getRegex()) - ->isEqualTo('~~iu'); - } - - public function testMultipleRegexChanges() - { - $obj = new _Search(); - $obj - ->setSearchTerms('A new hope') - ->setRegexEntireString(false) - ->setRegexCaseInsensitive('sensitive'); - $this->string($obj->getRegex()) - ->isEqualTo('~A new hope~u'); - - $obj->setSearchTerms('Return of the jedi') - ->setRegexEntireString(true) - ->setRegexCaseInsensitive(''); - $this - ->string($obj->getRegex()) - ->isEqualTo('~^Return of the jedi$~iu'); - } - - public function testGrep() - { - include_once TMX . 'fr/cache_fr_gecko_strings.php'; - $obj = new _Search(); - $obj - ->setSearchTerms('marque'); - $this->array($obj->grep($tmx)) - ->isEqualTo( - [ - 'mobile/android/base/android_strings.dtd:bookmark' => 'Marquer cette page', - 'browser/chrome/browser/places/places.properties:bookmarkResultLabel' => 'Marque-page', - 'browser/chrome/browser/syncQuota.properties:collection.bookmarks.label' => 'Marque-pages', - 'browser/chrome/browser/places/bookmarkProperties.properties:dialogTitleAddMulti' => 'Nouveaux marque-pages', - 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label' => 'Marquer cette page', - ] - ); - - $obj - ->setSearchTerms('marquer cette'); - $this->array($obj->grep($tmx)) - ->isEqualTo( - [ - 'mobile/android/base/android_strings.dtd:bookmark' => 'Marquer cette page', - 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label' => 'Marquer cette page', - ] - ); - - $obj - ->setSearchTerms('...') - ->setRegexEntireString('entire_string'); - - $this->array($obj->grep($tmx)) - ->isEqualTo( - [ - 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label2' => '...', - ] - ); - - $obj - ->setSearchTerms('...') - ->setRegexEntireString('entire_string'); - - $this->array($obj->grep(['test_repo' => $tmx], false)) - ->isEqualTo( - [ - 'test_repo' => ['browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label2' => '...'], - ] - ); - } - - public function testSetRepository() - { - $obj = new _Search(); - $obj->setRepository('foobar'); - $this->string($obj->getRepository()) - ->isEqualTo('gecko_strings'); - - $obj->setRepository('gecko_strings'); - $this->string($obj->getRepository()) - ->isEqualTo('gecko_strings'); - } - - public function testSetSearchType() - { - $obj = new _Search(); - $obj->setSearchType('foobar'); - $this->string($obj->getSearchType()) - ->isEqualTo('strings'); - - $obj->setSearchType('entities'); - $this->string($obj->getSearchType()) - ->isEqualTo('entities'); - } - - public function testGetSearchTypes() - { - $obj = new _Search(); - $this->array($obj->getSearchTypes()) - ->isEqualTo(['strings', 'entities', 'strings_entities']); - } - - public function testSetLocales() - { - $obj = new _Search(); - $obj->setLocales(['en-US', 'fr', 'de', 'it']); - $this->string($obj->getLocale('source')) - ->isEqualTo('en-US'); - $this->string($obj->getLocale('target')) - ->isEqualTo('fr'); - $this->string($obj->getLocale('extra')) - ->isEqualTo('de'); - - $obj->setLocales(['en-US', 'fr', 'fr']); - $this->string($obj->getLocale('source')) - ->isEqualTo('en-US'); - $this->string($obj->getLocale('target')) - ->isEqualTo('fr'); - $this->string($obj->getLocale('extra')) - ->isEqualTo(''); - } -} diff --git a/tests/units/Transvision/SearchTest.php b/tests/units/Transvision/SearchTest.php new file mode 100644 index 00000000..d55d615b --- /dev/null +++ b/tests/units/Transvision/SearchTest.php @@ -0,0 +1,223 @@ +assertSame($obj->getSearchTerms(), ''); + $this + ->assertSame($obj->getRegex(), ''); + $this + ->assertSame($obj->isCaseSensitive(), false); + $this + ->assertSame($obj->isEachWord(), false); + $this + ->assertSame($obj->isEntireString(), false); + $this + ->assertSame($obj->getRegexSearchTerms(), ''); + $this + ->assertSame($obj->getRepository(), 'gecko_strings'); + $this + ->assertSame($obj->getSearchType(), 'strings'); + $this + ->assertSame($obj->getLocale('source'), ''); + $this + ->assertEqualsCanonicalizing($obj->getFormSearchOptions(), + [ + 'case_sensitive', 'entire_string', 'repo', + 'search_type', 'each_word', 'entire_words', + ]); + $this + ->assertEqualsCanonicalizing($obj->getFormCheckboxes(), + [ + 'case_sensitive', 'entire_string', + 'each_word', 'entire_words', + ]); + } + + public function testSetSearchTerms() + { + $obj = new Search(); + $obj->setSearchTerms(' foobar '); + $this + ->assertSame($obj->getSearchTerms(), ' foobar '); + $this + ->assertSame($obj->getRegexSearchTerms(), ' foobar '); + } + + public function testSetRegexSearchTerms() + { + $obj = new Search(); + $obj->setRegexSearchTerms('A new hope'); + $this + ->assertSame($obj->getRegexSearchTerms(), 'A new hope'); + $this + ->assertSame($obj->getRegex(), '~A new hope~iu'); + } + + public function testSetRegexCaseInsensitive() + { + $obj = new Search(); + + // Test assertSames (as passed from GET) + $obj->setRegexCaseInsensitive('sensitive'); + $this + ->assertSame($obj->getRegex(), '~~u'); + + $obj->setRegexCaseInsensitive(''); + $this + ->assertSame($obj->getRegex(), '~~iu'); + + // Test boolean values + $obj->setRegexCaseInsensitive(true); + $this + ->assertSame($obj->getRegex(), '~~u'); + + $obj->setRegexCaseInsensitive(false); + $this + ->assertSame($obj->getRegex(), '~~iu'); + } + + public function testSetRegexEntireWords() + { + $obj = new Search(); + $obj->setRegexEntireWords('entire_words'); + + $this + ->assertSame($obj->isEntireWords(), true); + $this + ->assertSame($obj->getRegex(), '~\b\b~iu'); + + $obj->setRegexEntireWords(false); + $this + ->assertSame($obj->isEntireWords(), false); + $this + ->assertSame($obj->getRegex(), '~~iu'); + } + + public function testSetRegexEntireString() + { + $obj = new Search(); + $obj->setRegexEntireString('entire_string'); + $this + ->assertSame($obj->isEntireString(), true); + $this + ->assertSame($obj->getRegex(), '~^$~iu'); + + $obj->setRegexEntireString(false); + $this + ->assertSame($obj->isEntireString(), false); + $this + ->assertSame($obj->getRegex(), '~~iu'); + } + + public function testMultipleRegexChanges() + { + $obj = new Search(); + $obj + ->setSearchTerms('A new hope') + ->setRegexEntireString(false) + ->setRegexCaseInsensitive('sensitive'); + $this->assertSame($obj->getRegex(), '~A new hope~u'); + + $obj->setSearchTerms('Return of the jedi') + ->setRegexEntireString(true) + ->setRegexCaseInsensitive(''); + $this + ->assertSame($obj->getRegex(), '~^Return of the jedi$~iu'); + } + + public function testGrep() + { + include TMX . 'fr/cache_fr_gecko_strings.php'; + $obj = new Search(); + $obj + ->setSearchTerms('marque'); + $this->assertEqualsCanonicalizing($obj->grep($tmx), + [ + 'mobile/android/base/android_strings.dtd:bookmark' => 'Marquer cette page', + 'browser/chrome/browser/places/places.properties:bookmarkResultLabel' => 'Marque-page', + 'browser/chrome/browser/syncQuota.properties:collection.bookmarks.label' => 'Marque-pages', + 'browser/chrome/browser/places/bookmarkProperties.properties:dialogTitleAddMulti' => 'Nouveaux marque-pages', + 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label' => 'Marquer cette page', + ] + ); + + $obj + ->setSearchTerms('marquer cette'); + $this->assertEqualsCanonicalizing($obj->grep($tmx), + [ + 'mobile/android/base/android_strings.dtd:bookmark' => 'Marquer cette page', + 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label' => 'Marquer cette page', + ] + ); + + $obj + ->setSearchTerms('...') + ->setRegexEntireString('entire_string'); + + $this->assertEqualsCanonicalizing($obj->grep($tmx), + [ + 'browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label2' => '...', + ] + ); + + $obj + ->setSearchTerms('...') + ->setRegexEntireString('entire_string'); + + $this->assertEqualsCanonicalizing($obj->grep(['test_repo' => $tmx], false), + [ + 'test_repo' => ['browser/chrome/browser/browser.dtd:bookmarkThisPageCmd.label2' => '...'], + ] + ); + } + + public function testSetRepository() + { + $obj = new Search(); + $obj->setRepository('foobar'); + $this->assertSame($obj->getRepository(), 'gecko_strings'); + + $obj->setRepository('gecko_strings'); + $this->assertSame($obj->getRepository(), 'gecko_strings'); + } + + public function testSetSearchType() + { + $obj = new Search(); + $obj->setSearchType('foobar'); + $this->assertSame($obj->getSearchType(), 'strings'); + + $obj->setSearchType('entities'); + $this->assertSame($obj->getSearchType(), 'entities'); + } + + public function testGetSearchTypes() + { + $obj = new Search(); + $this->assertEqualsCanonicalizing($obj->getSearchTypes(), ['strings', 'entities', 'strings_entities']); + } + + public function testSetLocales() + { + $obj = new Search(); + $obj->setLocales(['en-US', 'fr', 'de', 'it']); + $this->assertSame($obj->getLocale('source'), 'en-US'); + $this->assertSame($obj->getLocale('target'), 'fr'); + $this->assertSame($obj->getLocale('extra'), 'de'); + + $obj->setLocales(['en-US', 'fr', 'fr']); + $this->assertSame($obj->getLocale('source'), 'en-US'); + $this->assertSame($obj->getLocale('target'), 'fr'); + $this->assertSame($obj->getLocale('extra'), ''); + } +} diff --git a/tests/units/Transvision/ShowResults.php b/tests/units/Transvision/ShowResultsTest.php similarity index 86% rename from tests/units/Transvision/ShowResults.php rename to tests/units/Transvision/ShowResultsTest.php index a3dc568b..48bef52d 100644 --- a/tests/units/Transvision/ShowResults.php +++ b/tests/units/Transvision/ShowResultsTest.php @@ -1,14 +1,15 @@ array($obj->getTMXResults($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->getTMXResults($a, $b), $c); } - public function getTMXResultsReposDP() + public static function getTMXResultsReposDP() { include TMX . 'en-US/cache_en-US_gecko_strings.php'; $source['test_repo'] = $tmx; @@ -61,18 +59,15 @@ public function getTMXResultsReposDP() ]; } - /** - * @dataProvider getTMXResultsReposDP - */ + #[DataProvider('getTMXResultsReposDP')] public function testGetTMXResultsRepos($a, $b, $c) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->array($obj->getTMXResultsRepos($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->getTMXResultsRepos($a, $b), $c); } - public function getTranslationMemoryResultsDP() + public static function getTranslationMemoryResultsDP() { include TMX . 'en-US/cache_en-US_gecko_strings.php'; $source = $tmx; @@ -120,36 +115,30 @@ public function getTranslationMemoryResultsDP() ]; } - /** - * @dataProvider getTranslationMemoryResultsDP - */ + #[DataProvider('getTranslationMemoryResultsDP')] public function testGetTranslationMemoryResults($a, $b, $c) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->array($obj->getTranslationMemoryResults($a, $b, 4)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->getTranslationMemoryResults($a, $b, 4), $c); } - public function formatEntityDP() + public static function formatEntityDP() { return [ ['browser/chrome/browser/browser.dtd:historyHomeCmd.label', false], ]; } - /** - * @dataProvider formatEntityDP - */ + #[DataProvider('formatEntityDP')] public function testFormatEntity($a, $b) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->string($obj->formatEntity($a, $b)) - ->isEqualTo('browser • chrome • browser • browser.dtd
    historyHomeCmd.label'); + ->assertSame($obj->formatEntity($a, $b), 'browser • chrome • browser • browser.dtd
    historyHomeCmd.label'); } - public function getStringFromEntityDP() + public static function getStringFromEntityDP() { return [ [ @@ -170,18 +159,15 @@ public function getStringFromEntityDP() ]; } - /** - * @dataProvider getStringFromEntityDP - */ + #[DataProvider('getStringFromEntityDP')] public function testGetStringFromEntity($a, $b, $c) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->variable($obj->getStringFromEntity($a, $b)) - ->isIdenticalTo($c); + ->assertEqualsCanonicalizing($obj->getStringFromEntity($a, $b), $c); } - public function getStringFromEntityReposDP() + public static function getStringFromEntityReposDP() { return [ [ @@ -217,18 +203,15 @@ public function getStringFromEntityReposDP() ]; } - /** - * @dataProvider getStringFromEntityReposDP - */ + #[DataProvider('getStringFromEntityReposDP')] public function testGetStringFromEntityRepos($a, $b, $c, $d) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->variable($obj->getStringFromEntityRepos($a, $b, $c)) - ->isIdenticalTo($d); + ->assertEqualsCanonicalizing($obj->getStringFromEntityRepos($a, $b, $c), $d); } - public function getRepositorySearchResultsDP() + public static function getRepositorySearchResultsDP() { return [ // Simple search @@ -280,18 +263,15 @@ public function getRepositorySearchResultsDP() ]; } - /** - * @dataProvider getRepositorySearchResultsDP - */ + #[DataProvider('getRepositorySearchResultsDP')] public function testGeRepositorySearchResults($a, $b, $c) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->array($obj->getRepositorySearchResults($a, $b)) - ->isIdenticalTo($c); + ->assertEqualsCanonicalizing($obj->getRepositorySearchResults($a, $b), $c); } - public function searchEntitiesDP() + public static function searchEntitiesDP() { return [ [ @@ -363,40 +343,38 @@ public function searchEntitiesDP() ]; } - /** - * @dataProvider searchEntitiesDP - */ + #[DataProvider('searchEntitiesDP')] public function testSearchEntities($a, $b, $c, $d) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->array($obj->searchEntities($a, $b, $c)) - ->isEqualTo($d); + ->assertEqualsCanonicalizing($obj->searchEntities($a, $b, $c), $d); } public function testGetSuggestionsResults() { - $obj = new _ShowResults(); + $obj = new ShowResults(); include TMX . 'en-US/cache_en-US_gecko_strings.php'; $source = $tmx; include TMX . 'fr/cache_fr_gecko_strings.php'; $target = $tmx; $this - ->array($obj->getSuggestionsResults($source, $target, 'Bookmark')) - ->isEqualTo(['Bookmark', 'Bookmarks', 'New Bookmarks', + ->assertEqualsCanonicalizing($obj->getSuggestionsResults($source, $target, 'Bookmark'), + ['Bookmark', 'Bookmarks', 'New Bookmarks', 'Bookmark This Page', 'Find in Finder', 'Nouveaux marque-pages', 'Marque-page', 'Marque-pages', - 'Marquer cette page', 'Ouvrir dans le Finder', ]) - ->array($obj->getSuggestionsResults($source, $target, 'Bookmark', 10)) - ->isEqualTo(['Bookmark', 'Bookmarks', 'New Bookmarks', + 'Marquer cette page', 'Ouvrir dans le Finder', ]); + $this + ->assertEqualsCanonicalizing($obj->getSuggestionsResults($source, $target, 'Bookmark', 10), + ['Bookmark', 'Bookmarks', 'New Bookmarks', 'Bookmark This Page', 'Find in Finder', 'Nouveaux marque-pages', 'Marque-page', 'Marque-pages', - 'Marquer cette page', 'Ouvrir dans le Finder', ]) - ->array($obj->getSuggestionsResults($source, $target, 'Bookmark', 3)) - ->isEqualTo(['Bookmark', 'Nouveaux marque-pages']); + 'Marquer cette page', 'Ouvrir dans le Finder', ]); + $this + ->assertEqualsCanonicalizing($obj->getSuggestionsResults($source, $target, 'Bookmark', 3), ['Bookmark', 'Nouveaux marque-pages']); } - public function buildErrorStringDP() + public static function buildErrorStringDP() { return [ [ @@ -437,18 +415,15 @@ public function buildErrorStringDP() ]; } - /** - * @dataProvider buildErrorStringDP - */ + #[DataProvider('buildErrorStringDP')] public function testBuildErrorString($a, $b, $c) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->string($obj->buildErrorString($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->buildErrorString($a, $b), $c); } - public function getEditLinkDP() + public static function getEditLinkDP() { return [ // Pontoon links @@ -569,18 +544,15 @@ public function getEditLinkDP() ]; } - /** - * @dataProvider getEditLinkDP - */ + #[DataProvider('getEditLinkDP')] public function testGetEditLink($a, $b, $c, $d, $e, $f) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->string($obj->getEditLink($a, $b, $c, $d, $e)) - ->isEqualTo($f); + ->assertEqualsCanonicalizing($obj->getEditLink($a, $b, $c, $d, $e), $f); } - public function buildComponentsFilterDP() + public static function buildComponentsFilterDP() { return [ [ @@ -598,14 +570,11 @@ public function buildComponentsFilterDP() ]; } - /** - * @dataProvider buildComponentsFilterDP - */ + #[DataProvider('buildComponentsFilterDP')] public function testBuildComponentsFilter($a, $b) { - $obj = new _ShowResults(); + $obj = new ShowResults(); $this - ->variable($obj->buildComponentsFilter($a)) - ->isIdenticalTo($b); + ->assertEqualsCanonicalizing($obj->buildComponentsFilter($a), $b); } } diff --git a/tests/units/Transvision/Strings.php b/tests/units/Transvision/StringsTest.php similarity index 61% rename from tests/units/Transvision/Strings.php rename to tests/units/Transvision/StringsTest.php index bbb424f0..83ab10e3 100644 --- a/tests/units/Transvision/Strings.php +++ b/tests/units/Transvision/StringsTest.php @@ -1,14 +1,15 @@ string($obj->mtrim($a)) - ->isEqualTo($b); + ->assertEqualsCanonicalizing($obj->mtrim($a), $b); } - public function startsWithDP() + public static function startsWithDP() { return [ ['it is raining', 'it', true], @@ -39,18 +37,15 @@ public function startsWithDP() ]; } - /** - * @dataProvider startsWithDP - */ + #[DataProvider('startsWithDP')] public function testStartsWith($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->boolean($obj->startsWith($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->startsWith($a, $b), $c); } - public function endsWithDP() + public static function endsWithDP() { return [ ['it is raining', 'ing', true], @@ -60,18 +55,15 @@ public function endsWithDP() ]; } - /** - * @dataProvider endsWithDP - */ + #[DataProvider('endsWithDP')] public function testEndsWith($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->boolean($obj->endsWith($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->endsWith($a, $b), $c); } - public function inStringWithDP() + public static function inStringWithDP() { return [ ['La maison est blanche', 'blanche', false, true], @@ -85,18 +77,15 @@ public function inStringWithDP() ]; } - /** - * @dataProvider inStringWithDP - */ + #[DataProvider('inStringWithDP')] public function testInString($a, $b, $c, $d) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->boolean($obj->inString($a, $b, $c)) - ->isEqualTo($d); + ->assertSame($obj->inString($a, $b, $c), $d); } - public function multipleStringReplaceDP() + public static function multipleStringReplaceDP() { return [ [ @@ -112,29 +101,24 @@ public function multipleStringReplaceDP() ]; } - /** - * @dataProvider multipleStringReplaceDP - */ + #[DataProvider('multipleStringReplaceDP')] public function testmultipleStringReplace($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->string($obj->multipleStringReplace($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->multipleStringReplace($a, $b), $c); } public function testHighlightSpecial() { - $obj = new _Strings(); + $obj = new Strings(); $this - ->string($obj->highlightSpecial('Foo is bar ; Bar is Foo…')) - ->isEqualTo('Foo is bar ; Bar is Foo'); + ->assertSame($obj->highlightSpecial('Foo is bar ; Bar is Foo…'), 'Foo is bar ; Bar is Foo'); $this - ->string($obj->highlightSpecial('Foo is bar ; Bar is Foo…', false)) - ->isEqualTo('Foo is bar ; Bar is Foo'); + ->assertSame($obj->highlightSpecial('Foo is bar ; Bar is Foo…', false), 'Foo is bar ; Bar is Foo'); } - public function markStringDP() + public static function markStringDP() { return [ ['in', '@@missing@@', '@@missing@@'], @@ -147,18 +131,15 @@ public function markStringDP() ]; } - /** - * @dataProvider markStringDP - */ + #[DataProvider('markStringDP')] public function testMarkString($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->string($obj->markString($a, $b, $c)) - ->isEqualTo($c); + ->assertSame($obj->markString($a, $b), $c); } - public function highlightStringDP() + public static function highlightStringDP() { return [ ['@@missing@@', '@@missing@@'], @@ -170,18 +151,15 @@ public function highlightStringDP() ]; } - /** - * @dataProvider highlightStringDP - */ + #[DataProvider('highlightStringDP')] public function testHighlightString($a, $b) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->string($obj->highlightString($a)) - ->isEqualTo($b); + ->assertSame($obj->highlightString($a), $b); } - public function getLengthDP() + public static function getLengthDP() { return [ ['Le cheval blanc ', 17], @@ -189,18 +167,15 @@ public function getLengthDP() ]; } - /** - * @dataProvider getLengthDP - */ + #[DataProvider('getLengthDP')] public function testGetLength($a, $b) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->integer($obj->getLength($a)) - ->isEqualTo($b); + ->assertSame($obj->getLength($a), $b); } - public function getSimilarDP() + public static function getSimilarDP() { return [ [ @@ -218,18 +193,15 @@ public function getSimilarDP() ]; } - /** - * @dataProvider getSimilarDP - */ + #[DataProvider('getSimilarDP')] public function testGetSimilar($a, $b, $c, $d) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->array($obj->getSimilar($a, $b, $c)) - ->isEqualTo($d); + ->assertSame($obj->getSimilar($a, $b, $c), $d); } - public function getLevenshteinUTF8DP() + public static function getLevenshteinUTF8DP() { return [ ['notre', 'nôtre', 1], @@ -242,39 +214,33 @@ public function getLevenshteinUTF8DP() ]; } - /** - * @dataProvider getLevenshteinUTF8DP - */ + #[DataProvider('getLevenshteinUTF8DP')] public function testLevenshteinUTF8($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->integer($obj->LevenshteinUTF8($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->LevenshteinUTF8($a, $b), $c); } - public function getLevenshteinQualityDP() + public static function getLevenshteinQualityDP() { - // We use divisions so as to have real precise numbers for float comparizon + // We use divisions so as to have real precise numbers for float comparison return [ ['notre', 'nôtre', (float) 80], ['웹', '으', (float) 0], - ['हिस्सा', 'हमारे', (float) 100 / 6], + ['हिस्सा', 'हमारे', (float) round(100 / 6, 5)], ['hello', 'melon', (float) 40], - ['കട', 'കടല', (float) 100 / 1.5], + ['കട', 'കടല', (float) round(100 / 1.5, 5)], ['കട', 'കല', (float) 50], - ['കട', 'കടി', (float) 100 / 1.5], + ['കട', 'കടി', (float) round(100 / 1.5, 5)], ]; } - /** - * @dataProvider getLevenshteinQualityDP - */ + #[DataProvider('getLevenshteinQualityDP')] public function testLevenshteinQuality($a, $b, $c) { - $obj = new _Strings(); + $obj = new Strings(); $this - ->float($obj->levenshteinQuality($a, $b)) - ->isNearlyEqualTo($c); + ->assertSame($obj->levenshteinQuality($a, $b), $c); } } diff --git a/tests/units/Transvision/TMX.php b/tests/units/Transvision/TMXTest.php similarity index 78% rename from tests/units/Transvision/TMX.php rename to tests/units/Transvision/TMXTest.php index 34ddc8b7..52999039 100644 --- a/tests/units/Transvision/TMX.php +++ b/tests/units/Transvision/TMXTest.php @@ -1,15 +1,18 @@ -
    +
    ' . "\n\t" . '' @@ -44,18 +48,17 @@ public function createDP() ]; } - /** - * @dataProvider createDP - */ - public function testCreate($a, $b, $c, $d) + #[DataProvider('createDP')] + public function testCreate($a, $b, $c, $d, $e) { - $obj = new _TMX(); - $this->string($obj->create($a, $b, $c)) - ->isEqualTo($d); + $obj = new TMX(); + $this->assertSame($obj->create($a, $b, $c, $d), $e); } - public function createOmegatDP() + public static function createOmegatDP() { + $creationDate = date('c'); + return [ [ [ @@ -71,10 +74,11 @@ public function createOmegatDP() ], 'fr', 'en-US', + $creationDate, ' -
    +
    ' . "\n\t" . '' . "\n\t\t" . 'shared/date/date.properties' @@ -102,13 +106,10 @@ public function createOmegatDP() ]; } - /** - * @dataProvider createOmegatDP - */ - public function testCreateOmegat($a, $b, $c, $d) + #[DataProvider('createOmegatDP')] + public function testCreateOmegat($a, $b, $c, $d, $e) { - $obj = new _TMX(); - $this->string($obj->createOmegat($a, $b, $c)) - ->isEqualTo($d); + $obj = new TMX(); + $this->assertSame($obj->createOmegat($a, $b, $c, $d), $e); } } diff --git a/tests/units/Transvision/Utils.php b/tests/units/Transvision/UtilsTest.php similarity index 64% rename from tests/units/Transvision/Utils.php rename to tests/units/Transvision/UtilsTest.php index 1ad02669..c435cfa5 100644 --- a/tests/units/Transvision/Utils.php +++ b/tests/units/Transvision/UtilsTest.php @@ -1,16 +1,17 @@ string($obj->secureText($a)) - ->isEqualTo($b); + ->assertSame($obj->secureText($a), $b); } - public function uniqueWordsDP() + public static function uniqueWordsDP() { return [ [ @@ -47,54 +45,45 @@ public function uniqueWordsDP() ]; } - /** - * @dataProvider uniqueWordsDP - */ + #[DataProvider('uniqueWordsDP')] public function testUniqueWords($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->array($obj->uniqueWords($a)) - ->isEqualTo($b); + ->assertSame($obj->uniqueWords($a), $b); } - public function checkboxDefaultOption1DP() + public static function checkboxDefaultOption1DP() { return [ ['es-ES', 'es-ES', ' checked="checked"'], ]; } - /** - * @dataProvider checkboxDefaultOption1DP - */ + #[DataProvider('checkboxDefaultOption1DP')] public function testCheckboxDefaultOption1($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->checkboxDefaultOption($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->checkboxDefaultOption($a, $b), $c); } - public function checkboxDefaultOption2DP() + public static function checkboxDefaultOption2DP() { return [ ['es-ES', 'en-US', false], ]; } - /** - * @dataProvider checkboxDefaultOption2DP - */ + #[DataProvider('checkboxDefaultOption2DP')] public function testCheckboxDefaultOption2($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->boolean($obj->checkboxDefaultOption($a, $b)) - ->isEqualTo($c); + ->assertSame($obj->checkboxDefaultOption($a, $b), $c); } - public function checkBoxState2DP() + public static function checkBoxState2DP() { $_GET['t2t'] = 'somedata'; @@ -103,36 +92,30 @@ public function checkBoxState2DP() ]; } - /** - * @dataProvider checkBoxState2DP - */ + #[DataProvider('checkBoxState2DP')] public function testCheckboxState2($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->checkboxState($a, $b)) - ->isEqualTo(' checked="checked"'); + ->assertSame($obj->checkboxState($a, $b), ' checked="checked"'); } - public function checkBoxState3DP() + public static function checkBoxState3DP() { return [ ['some string', null], ]; } - /** - * @dataProvider checkBoxState3DP - */ + #[DataProvider('checkBoxState3DP')] public function testCheckboxState3($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->checkboxState($a, $b)) - ->isEqualTo(' checked="checked"'); + ->assertSame($obj->checkboxState($a, $b), ' checked="checked"'); } - public function getHtmlSelectOptionsDP() + public static function getHtmlSelectOptionsDP() { return [ [ @@ -143,18 +126,15 @@ public function getHtmlSelectOptionsDP() ]; } - /** - * @dataProvider getHtmlSelectOptionsDP - */ + #[DataProvider('getHtmlSelectOptionsDP')] public function testGetHtmlSelectOptions($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->getHtmlSelectOptions($a, $b, $c)) - ->isEqualTo(''); + ->assertEqualsCanonicalizing($obj->getHtmlSelectOptions($a, $b, $c), ''); } - public function cleanStringDP() + public static function cleanStringDP() { return [ [ @@ -168,18 +148,15 @@ public function cleanStringDP() ]; } - /** - * @dataProvider cleanStringDP - */ + #[DataProvider('cleanStringDP')] public function testCleanString($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->cleanString($a)) - ->isEqualTo($b); + ->assertSame($obj->cleanString($a), $b); } - public function checkAbnormalStringLengthDP() + public static function checkAbnormalStringLengthDP() { return [ [ @@ -205,18 +182,15 @@ public function checkAbnormalStringLengthDP() ]; } - /** - * @dataProvider checkAbnormalStringLengthDP - */ + #[DataProvider('checkAbnormalStringLengthDP')] public function testCheckAbnormalStringLength($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->checkAbnormalStringLength($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->checkAbnormalStringLength($a, $b), $c); } - public function checkAbnormalStringLength2DP() + public static function checkAbnormalStringLength2DP() { return [ ['Add Bookmarks', 'Ajouter des marque-pages', false], @@ -224,34 +198,28 @@ public function checkAbnormalStringLength2DP() ]; } - /** - * @dataProvider checkAbnormalStringLength2DP - */ + #[DataProvider('checkAbnormalStringLength2DP')] public function testCheckAbnormalStringLength2($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->boolean($obj->checkAbnormalStringLength($a, $b)) - ->isEqualTo($c); + ->assertEqualsCanonicalizing($obj->checkAbnormalStringLength($a, $b), $c); } public function testGetRepoStrings() { - $obj = new _Utils(); + $obj = new Utils(); $this - ->array($obj->getRepoStrings('fr', 'gecko_strings')) - ->contains('Ouvrir dans le Finder'); + ->assertContains('Ouvrir dans le Finder', $obj->getRepoStrings('fr', 'gecko_strings')); $results = $obj->getRepoStrings('fr', 'gecko_strings', false); $this - ->array($results) - ->hasKey('gecko_strings'); + ->assertArrayHasKey('gecko_strings', $results); $this - ->array($results['gecko_strings']) - ->contains('Ouvrir dans le Finder'); + ->assertContains('Ouvrir dans le Finder', $results['gecko_strings']); } - public function flattenTMXDP() + public static function flattenTMXDP() { return [ [ @@ -269,18 +237,15 @@ public function flattenTMXDP() ]; } - /** - * @dataProvider flattenTMXDP - */ + #[DataProvider('flattenTMXDP')] public function testFlattenTMX($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->array($obj->flattenTMX($a)) - ->isEqualTo($b); + ->assertSame($obj->flattenTMX($a), $b); } - public function getOrSetDP() + public static function getOrSetDP() { return [ [ @@ -310,15 +275,12 @@ public function getOrSetDP() ]; } - /** - * @dataProvider getOrSetDP - */ + #[DataProvider('getOrSetDP')] public function testGetOrSet($a, $b, $c, $d) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->getOrSet($a, $b, $c)) - ->isEqualTo($d); + ->assertEqualsCanonicalizing($obj->getOrSet($a, $b, $c), $d); } public function afterTestMethod($method) @@ -332,7 +294,7 @@ public function afterTestMethod($method) } } - public function redYellowGreenDP() + public static function redYellowGreenDP() { return [ ['34.13', '255,168,0'], @@ -340,18 +302,15 @@ public function redYellowGreenDP() ]; } - /** - * @dataProvider redYellowGreenDP - */ + #[DataProvider('redYellowGreenDP')] public function testRedYellowGreen($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->redYellowGreen($a)) - ->contains($b); + ->assertEqualsCanonicalizing($obj->redYellowGreen($a), $b); } - public function pluralizeDP() + public static function pluralizeDP() { return [ ['42', 'test', '42 tests'], @@ -359,24 +318,21 @@ public function pluralizeDP() ]; } - /** - * @dataProvider pluralizeDP - */ + #[DataProvider('pluralizeDP')] public function testPluralize($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->pluralize($a, $b)) - ->contains($c); + ->assertSame($obj->pluralize($a, $b), $c); } - public function agoDP() + public static function agoDP() { $data = [ [ - (new DateTime())->modify('-2 seconds'), + (new DateTime())->modify('-30 seconds'), (new DateTime()), - '2 seconds ago', + '30 seconds ago', ], [ (new DateTime())->modify('-10 hours'), @@ -398,39 +354,20 @@ public function agoDP() (new DateTime()), '1 year', ], - ]; - - $data = array_merge( - $data, - [ - [ - (new DateTime())->modify('-2 seconds'), - '', - '2 seconds ago', - ], - [ - (new DateTime())->modify('-1 hour'), - '', - '1 hour ago', - ], - ] - ); + ]; return $data; } - /** - * @dataProvider agoDP - */ + #[DataProvider('agoDP')] public function testAgo($a, $b, $c) { - $obj = new _Utils(); + $obj = new Utils(); $this - ->string($obj->ago($a, $b)) - ->contains($c); + ->assertSame($obj->ago($a, $b), $c); } - public function redirectToAPIDP() + public static function redirectToAPIDP() { return [ [ @@ -448,21 +385,18 @@ public function redirectToAPIDP() ]; } - /** - * @dataProvider redirectToAPIDP - */ + #[DataProvider('redirectToAPIDP')] public function testRedirectToAPI($a, $b) { - $obj = new _Utils(); + $obj = new Utils(); $_SERVER['REQUEST_URI'] = $a; $_SERVER['QUERY_STRING'] = isset(parse_url($a)['query']) ? parse_url($a)['query'] : null; $this - ->string($obj->redirectToAPI()) - ->isEqualTo($b); + ->assertSame($obj->redirectToAPI(), $b); } - public function APIPromotionDP() + public static function APIPromotionDP() { return [ [ @@ -479,30 +413,29 @@ public function APIPromotionDP() ], ]; } - /** - * @dataProvider APIPromotionDP - */ + #[DataProvider('APIPromotionDP')] public function testAPIPromotion($a, $b, $c, $d) { - $obj = new _Utils(); + $obj = new Utils(); $_SERVER['REQUEST_URI'] = $c; $_SERVER['QUERY_STRING'] = isset(parse_url($c)['query']) ? parse_url($c)['query'] : null; $this - ->string($obj->APIPromotion($a, $b)) - ->isEqualTo($d); + ->assertSame($obj->APIPromotion($a, $b), $d); } public function testGetScriptPerformances() { - $obj = new _Utils(); + $obj = new Utils(); $data = $obj->getScriptPerformances(); $this - ->array($data) - ->size->isEqualTo(3) - ->integer($data[0]) - ->float($data[1]) - ->float($data[2]); + ->assertCount(3, $data); + $this + ->assertIsInt($data[0]); + $this + ->assertIsFloat($data[1]); + $this + ->assertIsFloat($data[2]); } } diff --git a/tests/units/Transvision/VersionControl.php b/tests/units/Transvision/VersionControlTest.php similarity index 87% rename from tests/units/Transvision/VersionControl.php rename to tests/units/Transvision/VersionControlTest.php index 377c2e6e..48c56167 100644 --- a/tests/units/Transvision/VersionControl.php +++ b/tests/units/Transvision/VersionControlTest.php @@ -1,14 +1,15 @@ string($obj->getVCS($a)) - ->isEqualTo($b); + ->assertSame($obj->getVCS($a), $b); } - public function VCSRepoNameDP() + public static function VCSRepoNameDP() { return [ [ @@ -49,18 +47,15 @@ public function VCSRepoNameDP() ]; } - /** - * @dataProvider VCSRepoNameDP - */ + #[DataProvider('VCSRepoNameDP')] public function testVCSRepoName($a, $b) { $obj = new _VersionControl(); $this - ->string($obj->VCSRepoName($a)) - ->isEqualTo($b); + ->assertSame($obj->VCSRepoName($a), $b); } - public function gitPathDP() + public static function gitPathDP() { return [ [ @@ -108,18 +103,15 @@ public function gitPathDP() ]; } - /** - * @dataProvider gitPathDP - */ + #[DataProvider('gitPathDP')] public function testGitPath($a, $b, $c, $d) { $obj = new _VersionControl(); $this - ->string($obj->gitPath($a, $b, $c)) - ->isEqualTo($d); + ->assertSame($obj->gitPath($a, $b, $c), $d); } - public function getPathDP() + public static function getPathDP() { return [ [ @@ -179,14 +171,11 @@ public function getPathDP() ]; } - /** - * @dataProvider getPathDP - */ + #[DataProvider('getPathDP')] public function testGetPath($a, $b, $c, $d) { $obj = new _VersionControl(); $this - ->string($obj->getPath($a, $b, $c)) - ->isEqualTo($d); + ->assertSame($obj->getPath($a, $b, $c), $d); } } diff --git a/tests/units/Transvision/Xliff.php b/tests/units/Transvision/Xliff.php deleted file mode 100644 index c86e16cf..00000000 --- a/tests/units/Transvision/Xliff.php +++ /dev/null @@ -1,106 +0,0 @@ -getStrings(TEST_FILES . 'xliff/firefox-ios.xliff', 'firefox-ios.xliff', 'firefox_ios'); - - // Check total number of strings - $this - ->integer(count($strings)) - ->isEqualTo(15); - - // Check strings - $this - ->string($strings['firefox_ios/firefox-ios.xliff:4c8cc9416b11b77e88809ff17e7f180e']) - ->isEqualTo('Cronologia di navigazione'); - - $this - ->string($strings['firefox_ios/firefox-ios.xliff:f6b6d1aff4ade5b867d563d74b01a429']) - ->isEqualTo('Segnalibri pc desktop'); - - // Check escaped single straight quotes - $this - ->string($strings['firefox_ios/firefox-ios.xliff:e15c1a9a6082aa32623205328418a603']) - ->isEqualTo("Test con \'"); - - $this - ->string($strings['firefox_ios/firefox-ios.xliff:1348465d2e7136641805937598daaeda']) - ->isEqualTo("Test con \\\\\' già escaped"); - } - - public function testGetStringsReference() - { - $obj = new _Xliff(); - $strings = $obj->getStrings(TEST_FILES . 'xliff/firefox-ios.xliff', 'firefox-ios.xliff', 'firefox_ios', true); - - // Check total number of strings - $this - ->integer(count($strings)) - ->isEqualTo(16); - - // Check strings - $this - ->string($strings['firefox_ios/firefox-ios.xliff:4c8cc9416b11b77e88809ff17e7f180e']) - ->isEqualTo('Browsing History'); - - $this - ->string($strings['firefox_ios/firefox-ios.xliff:f6b6d1aff4ade5b867d563d74b01a429']) - ->isEqualTo('Desktop Bookmarks'); - - // Check escaped single straight quotes - $this - ->string($strings['firefox_ios/firefox-ios.xliff:e15c1a9a6082aa32623205328418a603']) - ->isEqualTo("Test with \'"); - - $this - ->string($strings['firefox_ios/firefox-ios.xliff:1348465d2e7136641805937598daaeda']) - ->isEqualTo("Test with \\\\\' already escaped"); - } - - public function generateStringID_DP() - { - return [ - [ - 'firefox_ios', - 'firefox-ios.xliff', - 'AccountTests/Info.plist', - 'Delete', - 'firefox_ios/firefox-ios.xliff:bb46926d0fcd6d43155f706a22b0f3fc', - ], - [ - 'firefox_ios', - 'firefox-ios.xliff', - 'DiffentFile/Info.plist', - 'Delete', - 'firefox_ios/firefox-ios.xliff:e3b9ee7a5b6b4e96f70c539d87aff9b0', - ], - [ - 'firefox_ios', - 'firefox-ios.xliff', - 'Client/3DTouchActions.strings', - 'Are you sure you want to clear all of your data? This will also close all open tabs.', - 'firefox_ios/firefox-ios.xliff:46e4ec3c64a0ce5a5d9c5f8bebd74325', - ], - ]; - } - - /** - * @dataProvider generateStringID_DP - */ - public function testGenerateStringID($a, $b, $c, $d, $e) - { - $obj = new _Xliff(); - $this - ->string($obj->generateStringID($a, $b, $c, $d)) - ->isEqualTo($e); - } -} diff --git a/tests/units/Transvision/XliffTest.php b/tests/units/Transvision/XliffTest.php new file mode 100644 index 00000000..328f5db0 --- /dev/null +++ b/tests/units/Transvision/XliffTest.php @@ -0,0 +1,94 @@ +getStrings(TEST_FILES . 'xliff/firefox-ios.xliff', 'firefox-ios.xliff', 'firefox_ios'); + + // Check total number of strings + $this + ->assertCount(15, $strings); + + // Check strings + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:4c8cc9416b11b77e88809ff17e7f180e'], 'Cronologia di navigazione'); + + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:f6b6d1aff4ade5b867d563d74b01a429'], 'Segnalibri pc desktop'); + + // Check escaped single straight quotes + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:e15c1a9a6082aa32623205328418a603'], "Test con \'"); + + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:1348465d2e7136641805937598daaeda'], "Test con \\\\\' già escaped"); + } + + public function testGetStringsReference() + { + $obj = new Xliff(); + $strings = $obj->getStrings(TEST_FILES . 'xliff/firefox-ios.xliff', 'firefox-ios.xliff', 'firefox_ios', true); + + // Check total number of strings + $this + ->assertCount(16, $strings); + + // Check strings + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:4c8cc9416b11b77e88809ff17e7f180e'], 'Browsing History'); + + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:f6b6d1aff4ade5b867d563d74b01a429'], 'Desktop Bookmarks'); + + // Check escaped single straight quotes + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:e15c1a9a6082aa32623205328418a603'], "Test with \'"); + + $this + ->assertSame($strings['firefox_ios/firefox-ios.xliff:1348465d2e7136641805937598daaeda'], "Test with \\\\\' already escaped"); + } + + public static function generateStringID_DP() + { + return [ + [ + 'firefox_ios', + 'firefox-ios.xliff', + 'AccountTests/Info.plist', + 'Delete', + 'firefox_ios/firefox-ios.xliff:bb46926d0fcd6d43155f706a22b0f3fc', + ], + [ + 'firefox_ios', + 'firefox-ios.xliff', + 'DiffentFile/Info.plist', + 'Delete', + 'firefox_ios/firefox-ios.xliff:e3b9ee7a5b6b4e96f70c539d87aff9b0', + ], + [ + 'firefox_ios', + 'firefox-ios.xliff', + 'Client/3DTouchActions.strings', + 'Are you sure you want to clear all of your data? This will also close all open tabs.', + 'firefox_ios/firefox-ios.xliff:46e4ec3c64a0ce5a5d9c5f8bebd74325', + ], + ]; + } + + #[DataProvider('generateStringID_DP')] + public function testGenerateStringID($a, $b, $c, $d, $e) + { + $obj = new Xliff(); + $this + ->assertSame($obj->generateStringID($a, $b, $c, $d), $e); + } +} diff --git a/tests/units/bootstrap.php b/tests/units/bootstrap.php index 36231bb6..8c28c970 100644 --- a/tests/units/bootstrap.php +++ b/tests/units/bootstrap.php @@ -1,7 +1,7 @@