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