+@pytest.fixture
+def temp_phplib_dir_with_migration(src_dir, tmp_path):
+ """
+ Return temporary phpdir with migration subdirectory and
+ PhraseSettingsToJson.php script inside.
+ """
+ migration_file = (src_dir / 'lib-php' / 'migration' / 'PhraseSettingsToJson.php').resolve()
+
+ phpdir = tmp_path / 'tempphp'
+ phpdir.mkdir()
+
+ (phpdir / 'migration').mkdir()
+ migration_dest_path = (phpdir / 'migration' / 'PhraseSettingsToJson.php').resolve()
+ copyfile(str(migration_file), str(migration_dest_path))
+
+ return phpdir
+
+
+@pytest.fixture
+def xml_wiki_content(src_dir):
+ """
+ return the content of the static xml test file.
+ """
+ xml_test_content_path = (src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt').resolve()
+ return xml_test_content_path.read_text()
+
+
+@pytest.fixture
+def default_phrases(table_factory):
+ table_factory('place_classtype_testclasstypetable_to_delete')
+ table_factory('place_classtype_testclasstypetable_to_keep')
+
+
+def test_fetch_existing_place_classtype_tables(sp_importer, table_factory):
+ """
+ Check for the fetch_existing_place_classtype_tables() method.
+ It should return the table just created.
+ """
+ table_factory('place_classtype_testclasstypetable')
+
+ sp_importer._fetch_existing_place_classtype_tables()
+ contained_table = sp_importer.table_phrases_to_delete.pop()
+ assert contained_table == 'place_classtype_testclasstypetable'
+
+def test_check_sanity_class(sp_importer):
+ """
+ Check for _check_sanity() method.
+ If a wrong class or type is given, an UsageError should raise.
+ If a good class and type are given, nothing special happens.
+ """
+
+ assert not sp_importer._check_sanity(SpecialPhrase('en', '', 'type', ''))
+ assert not sp_importer._check_sanity(SpecialPhrase('en', 'class', '', ''))
+
+ assert sp_importer._check_sanity(SpecialPhrase('en', 'class', 'type', ''))
+
+def test_load_white_and_black_lists(sp_importer):
+ """
+ Test that _load_white_and_black_lists() well return
+ black list and white list and that they are of dict type.
+ """
+ black_list, white_list = sp_importer._load_white_and_black_lists()
+
+ assert isinstance(black_list, dict) and isinstance(white_list, dict)
+
+def test_convert_php_settings(sp_importer, testfile_dir, tmp_path):
+ """
+ Test that _convert_php_settings_if_needed() convert the given
+ php file to a json file.
+ """
+ php_file = (testfile_dir / 'phrase_settings.php').resolve()
+
+ temp_settings = (tmp_path / 'phrase_settings.php').resolve()
+ copyfile(php_file, temp_settings)
+ sp_importer._convert_php_settings_if_needed(temp_settings)
+
+ assert (tmp_path / 'phrase_settings.json').is_file()
+
+def test_convert_settings_wrong_file(sp_importer):
+ """
+ Test that _convert_php_settings_if_needed() raise an exception
+ if the given file is not a valid file.
+ """
+ with pytest.raises(UsageError, match='random_file is not a valid file.'):
+ sp_importer._convert_php_settings_if_needed('random_file')
+
+def test_convert_settings_json_already_exist(sp_importer, testfile_dir):
+ """
+ Test that if we give to '_convert_php_settings_if_needed' a php file path
+ and that a the corresponding json file already exists, it is returned.
+ """
+ php_file = (testfile_dir / 'phrase_settings.php').resolve()
+ json_file = (testfile_dir / 'phrase_settings.json').resolve()
+
+ returned = sp_importer._convert_php_settings_if_needed(php_file)
+
+ assert returned == json_file