@@ -110,6 +110,12 @@ public function testCompleteWriteProcessAddFiles()
110
110
111
111
return new MockResponse (json_encode (['data ' => []]));
112
112
},
113
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
114
+ $ this ->assertSame ('GET ' , $ method );
115
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
116
+
117
+ return new MockResponse (json_encode (['data ' => ['languageMapping ' => []]]));
118
+ },
113
119
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
114
120
$ this ->assertSame ('POST ' , $ method );
115
121
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -188,6 +194,12 @@ public function testWriteAddFileServerError()
188
194
189
195
return new MockResponse (json_encode (['data ' => []]));
190
196
},
197
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
198
+ $ this ->assertSame ('GET ' , $ method );
199
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
200
+
201
+ return new MockResponse (json_encode (['data ' => ['languageMapping ' => []]]));
202
+ },
191
203
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
192
204
$ this ->assertSame ('POST ' , $ method );
193
205
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -260,6 +272,12 @@ public function testWriteUpdateFileServerError()
260
272
],
261
273
]));
262
274
},
275
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
276
+ $ this ->assertSame ('GET ' , $ method );
277
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
278
+
279
+ return new MockResponse (json_encode (['data ' => ['languageMapping ' => []]]));
280
+ },
263
281
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
264
282
$ this ->assertSame ('POST ' , $ method );
265
283
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -349,6 +367,12 @@ public function testWriteUploadTranslationsServerError()
349
367
],
350
368
]));
351
369
},
370
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
371
+ $ this ->assertSame ('GET ' , $ method );
372
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
373
+
374
+ return new MockResponse (json_encode (['data ' => ['languageMapping ' => []]]));
375
+ },
352
376
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
353
377
$ this ->assertSame ('POST ' , $ method );
354
378
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -442,6 +466,12 @@ public function testCompleteWriteProcessUpdateFiles()
442
466
],
443
467
]));
444
468
},
469
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
470
+ $ this ->assertSame ('GET ' , $ method );
471
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
472
+
473
+ return new MockResponse (json_encode (['data ' => ['languageMapping ' => []]]));
474
+ },
445
475
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
446
476
$ this ->assertSame ('POST ' , $ method );
447
477
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -512,6 +542,20 @@ public function testCompleteWriteProcessAddFileAndUploadTranslations(TranslatorB
512
542
],
513
543
]));
514
544
},
545
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
546
+ $ this ->assertSame ('GET ' , $ method );
547
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
548
+
549
+ return new MockResponse (json_encode ([
550
+ 'data ' => [
551
+ 'languageMapping ' => [
552
+ 'pt-PT ' => [
553
+ 'locale ' => 'pt ' ,
554
+ ],
555
+ ],
556
+ ],
557
+ ]));
558
+ },
515
559
'addStorage ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesFileContent ): ResponseInterface {
516
560
$ this ->assertSame ('POST ' , $ method );
517
561
$ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
@@ -542,6 +586,22 @@ public function testCompleteWriteProcessAddFileAndUploadTranslations(TranslatorB
542
586
$ this ->assertSame (sprintf ('https://api.crowdin.com/api/v2/projects/1/translations/%s ' , $ expectedLocale ), $ url );
543
587
$ this ->assertSame ('{"storageId":19,"fileId":12} ' , $ options ['body ' ]);
544
588
589
+ return new MockResponse ();
590
+ },
591
+ 'addStorage3 ' => function (string $ method , string $ url , array $ options = []) use ($ expectedMessagesTranslationsContent ): ResponseInterface {
592
+ $ this ->assertSame ('POST ' , $ method );
593
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/storages ' , $ url );
594
+ $ this ->assertSame ('Content-Type: application/octet-stream ' , $ options ['normalized_headers ' ]['content-type ' ][0 ]);
595
+ $ this ->assertSame ('Crowdin-API-FileName: messages.xlf ' , $ options ['normalized_headers ' ]['crowdin-api-filename ' ][0 ]);
596
+ $ this ->assertStringMatchesFormat ($ expectedMessagesTranslationsContent , $ options ['body ' ]);
597
+
598
+ return new MockResponse (json_encode (['data ' => ['id ' => 19 ]], ['http_code ' => 201 ]));
599
+ },
600
+ 'uploadTranslations2 ' => function (string $ method , string $ url , array $ options = []) use ($ expectedLocale ): ResponseInterface {
601
+ $ this ->assertSame ('POST ' , $ method );
602
+ $ this ->assertSame (sprintf ('https://api.crowdin.com/api/v2/projects/1/translations/%s ' , $ expectedLocale ), $ url );
603
+ $ this ->assertSame ('{"storageId":19,"fileId":12} ' , $ options ['body ' ]);
604
+
545
605
return new MockResponse ();
546
606
},
547
607
];
@@ -582,6 +642,33 @@ public static function getResponsesForProcessAddFileAndUploadTranslations(): \Ge
582
642
</file>
583
643
</xliff>
584
644
645
+ XLIFF
646
+ ];
647
+
648
+ $ translatorBagPt = new TranslatorBag ();
649
+ $ translatorBagPt ->addCatalogue ($ arrayLoader ->load ([
650
+ 'a ' => 'trans_en_a ' ,
651
+ ], 'en ' ));
652
+ $ translatorBagPt ->addCatalogue ($ arrayLoader ->load ([
653
+ 'a ' => 'trans_pt_a ' ,
654
+ ], 'pt ' ));
655
+
656
+ yield [$ translatorBagPt , 'pt-PT ' , <<<'XLIFF'
657
+ <?xml version="1.0" encoding="utf-8"?>
658
+ <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
659
+ <file source-language="en" target-language="pt" datatype="plaintext" original="file.ext">
660
+ <header>
661
+ <tool tool-id="symfony" tool-name="Symfony"/>
662
+ </header>
663
+ <body>
664
+ <trans-unit id="ypeBEso" resname="a">
665
+ <source>a</source>
666
+ <target>trans_pt_a</target>
667
+ </trans-unit>
668
+ </body>
669
+ </file>
670
+ </xliff>
671
+
585
672
XLIFF
586
673
];
587
674
@@ -632,25 +719,15 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
632
719
],
633
720
]));
634
721
},
635
- 'listLanguages ' => function (string $ method , string $ url, array $ options = [] ): ResponseInterface {
722
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
636
723
$ this ->assertSame ('GET ' , $ method );
637
- $ this ->assertSame ('https://api.crowdin.com/api/v2/languages?limit=500 ' , $ url );
638
- $ this ->assertSame ('Authorization: Bearer API_TOKEN ' , $ options ['normalized_headers ' ]['authorization ' ][0 ]);
724
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
639
725
640
726
return new MockResponse (json_encode ([
641
727
'data ' => [
642
- [
643
- 'data ' => [
644
- 'id ' => 'en-GB ' ,
645
- 'osxLocale ' => 'en_GB ' ,
646
- 'locale ' => 'en-GB ' ,
647
- ],
648
- ],
649
- [
650
- 'data ' => [
651
- 'id ' => 'fr ' ,
652
- 'osxLocale ' => 'fr_FR ' ,
653
- 'locale ' => 'fr-FR ' ,
728
+ 'languageMapping ' => [
729
+ 'pt-PT ' => [
730
+ 'locale ' => 'pt ' ,
654
731
],
655
732
],
656
733
],
@@ -770,25 +847,15 @@ public function testReadForDefaultLocaleAndOneDomain(string $locale, string $dom
770
847
],
771
848
]));
772
849
},
773
- 'listLanguages ' => function (string $ method , string $ url, array $ options = [] ): ResponseInterface {
850
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
774
851
$ this ->assertSame ('GET ' , $ method );
775
- $ this ->assertSame ('https://api.crowdin.com/api/v2/languages?limit=500 ' , $ url );
776
- $ this ->assertSame ('Authorization: Bearer API_TOKEN ' , $ options ['normalized_headers ' ]['authorization ' ][0 ]);
852
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
777
853
778
854
return new MockResponse (json_encode ([
779
855
'data ' => [
780
- [
781
- 'data ' => [
782
- 'id ' => 'en ' ,
783
- 'osxLocale ' => 'en_GB ' ,
784
- 'locale ' => 'en-GB ' ,
785
- ],
786
- ],
787
- [
788
- 'data ' => [
789
- 'id ' => 'fr ' ,
790
- 'osxLocale ' => 'fr_FR ' ,
791
- 'locale ' => 'fr-FR ' ,
856
+ 'languageMapping ' => [
857
+ 'pt-PT ' => [
858
+ 'locale ' => 'pt ' ,
792
859
],
793
860
],
794
861
],
@@ -874,25 +941,15 @@ public function testReadServerException()
874
941
],
875
942
]));
876
943
},
877
- 'listLanguages ' => function (string $ method , string $ url, array $ options = [] ): ResponseInterface {
944
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
878
945
$ this ->assertSame ('GET ' , $ method );
879
- $ this ->assertSame ('https://api.crowdin.com/api/v2/languages?limit=500 ' , $ url );
880
- $ this ->assertSame ('Authorization: Bearer API_TOKEN ' , $ options ['normalized_headers ' ]['authorization ' ][0 ]);
946
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
881
947
882
948
return new MockResponse (json_encode ([
883
949
'data ' => [
884
- [
885
- 'data ' => [
886
- 'id ' => 'en ' ,
887
- 'osxLocale ' => 'en_GB ' ,
888
- 'locale ' => 'en-GB ' ,
889
- ],
890
- ],
891
- [
892
- 'data ' => [
893
- 'id ' => 'fr ' ,
894
- 'osxLocale ' => 'fr_FR ' ,
895
- 'locale ' => 'fr-FR ' ,
950
+ 'languageMapping ' => [
951
+ 'pt-PT ' => [
952
+ 'locale ' => 'pt ' ,
896
953
],
897
954
],
898
955
],
@@ -933,25 +990,15 @@ public function testReadDownloadServerException()
933
990
],
934
991
]));
935
992
},
936
- 'listLanguages ' => function (string $ method , string $ url, array $ options = [] ): ResponseInterface {
993
+ 'getProject ' => function (string $ method , string $ url ): ResponseInterface {
937
994
$ this ->assertSame ('GET ' , $ method );
938
- $ this ->assertSame ('https://api.crowdin.com/api/v2/languages?limit=500 ' , $ url );
939
- $ this ->assertSame ('Authorization: Bearer API_TOKEN ' , $ options ['normalized_headers ' ]['authorization ' ][0 ]);
995
+ $ this ->assertSame ('https://api.crowdin.com/api/v2/projects/1/ ' , $ url );
940
996
941
997
return new MockResponse (json_encode ([
942
998
'data ' => [
943
- [
944
- 'data ' => [
945
- 'id ' => 'en ' ,
946
- 'osxLocale ' => 'en_GB ' ,
947
- 'locale ' => 'en-GB ' ,
948
- ],
949
- ],
950
- [
951
- 'data ' => [
952
- 'id ' => 'fr ' ,
953
- 'osxLocale ' => 'fr_FR ' ,
954
- 'locale ' => 'fr-FR ' ,
999
+ 'languageMapping ' => [
1000
+ 'pt-PT ' => [
1001
+ 'locale ' => 'pt ' ,
955
1002
],
956
1003
],
957
1004
],
0 commit comments