PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/web/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php

https://gitlab.com/mohamed_hussein/prodt
PHP | 237 lines | 206 code | 13 blank | 18 comment | 1 complexity | a4c0b0dd851ce134d16ff6cabddb8d03 MD5 | raw file
  1. <?php
  2. namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7;
  3. /**
  4. * Tests D7 i18n term localized source plugin.
  5. *
  6. * @covers \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation
  7. * @group taxonomy
  8. */
  9. class TermLocalizedTranslationTest extends TermTest {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected static $modules = ['taxonomy', 'migrate_drupal'];
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function providerSource() {
  18. $tests = parent::providerSource();
  19. for ($i = 1; $i < 4; $i++) {
  20. unset($tests[$i]);
  21. }
  22. foreach ($tests[0]['source_data']['taxonomy_term_data'] as $key => $value) {
  23. $tests[0]['source_data']['taxonomy_term_data'][$key]['language'] = 'und';
  24. $tests[0]['source_data']['taxonomy_term_data'][$key]['i18n_tsid'] = 0;
  25. }
  26. // The source data.
  27. $tests[0]['source_data']['i18n_string'] = [
  28. [
  29. 'lid' => 6,
  30. 'objectid' => 1,
  31. 'type' => 'term',
  32. 'property' => 'name',
  33. 'objectindex' => '1',
  34. 'format' => 0,
  35. ],
  36. [
  37. 'lid' => 7,
  38. 'objectid' => 1,
  39. 'type' => 'term',
  40. 'property' => 'description',
  41. 'objectindex' => '1',
  42. 'format' => 0,
  43. ],
  44. [
  45. 'lid' => 8,
  46. 'objectid' => 3,
  47. 'type' => 'term',
  48. 'property' => 'name',
  49. 'objectindex' => '3',
  50. 'format' => 0,
  51. ],
  52. [
  53. 'lid' => 9,
  54. 'objectid' => 4,
  55. 'type' => 'term',
  56. 'property' => 'description',
  57. 'objectindex' => '4',
  58. 'format' => 0,
  59. ],
  60. ];
  61. $tests[0]['source_data']['locales_target'] = [
  62. [
  63. 'lid' => 6,
  64. 'language' => 'fr',
  65. 'translation' => 'fr - name value 1',
  66. 'plid' => 0,
  67. 'plural' => 0,
  68. 'i18n_status' => 0,
  69. ],
  70. [
  71. 'lid' => 7,
  72. 'language' => 'fr',
  73. 'translation' => 'fr - description value 1',
  74. 'plid' => 0,
  75. 'plural' => 0,
  76. 'i18n_status' => 0,
  77. ],
  78. [
  79. 'lid' => 8,
  80. 'language' => 'zu',
  81. 'translation' => 'zu - name value 3',
  82. 'plid' => 0,
  83. 'plural' => 0,
  84. 'i18n_status' => 0,
  85. ],
  86. ];
  87. // The expected results.
  88. $tests[0]['expected_data'] = [
  89. [
  90. 'tid' => 1,
  91. 'vid' => 5,
  92. 'name' => 'name value 1 (name_field)',
  93. 'description' => 'description value 1 (description_field)',
  94. 'weight' => 0,
  95. 'is_container' => '',
  96. 'language' => 'fr',
  97. 'i18n_tsid' => '0',
  98. 'machine_name' => 'tags',
  99. 'tdlanguage' => 'und',
  100. 'lid' => '6',
  101. 'property' => 'name',
  102. 'ltlanguage' => 'fr',
  103. 'translation' => 'fr - name value 1',
  104. 'name_translated' => 'fr - name value 1',
  105. 'description_translated' => 'fr - description value 1',
  106. ],
  107. [
  108. 'tid' => 1,
  109. 'vid' => 5,
  110. 'name' => 'name value 1 (name_field)',
  111. 'description' => 'description value 1 (description_field)',
  112. 'weight' => 0,
  113. 'is_container' => '',
  114. 'language' => 'fr',
  115. 'i18n_tsid' => '0',
  116. 'machine_name' => 'tags',
  117. 'tdlanguage' => 'und',
  118. 'lid' => '7',
  119. 'property' => 'description',
  120. 'ltlanguage' => 'fr',
  121. 'translation' => 'fr - description value 1',
  122. 'name_translated' => 'fr - name value 1',
  123. 'description_translated' => 'fr - description value 1',
  124. ],
  125. ];
  126. $tests[0]['expected_count'] = NULL;
  127. // Get translations for the tags bundle.
  128. $tests[0]['configuration']['bundle'] = ['tags'];
  129. // The source data.
  130. $tests[1] = $tests[0];
  131. array_push($tests[1]['source_data']['i18n_string'],
  132. [
  133. 'lid' => 10,
  134. 'objectid' => 5,
  135. 'type' => 'term',
  136. 'property' => 'name',
  137. 'objectindex' => '5',
  138. 'format' => 0,
  139. ],
  140. [
  141. 'lid' => 11,
  142. 'objectid' => 5,
  143. 'type' => 'term',
  144. 'property' => 'description',
  145. 'objectindex' => '5',
  146. 'format' => 0,
  147. ]);
  148. array_push($tests[1]['source_data']['locales_target'],
  149. [
  150. 'lid' => 10,
  151. 'language' => 'fr',
  152. 'translation' => 'fr - name value 5',
  153. 'plid' => 0,
  154. 'plural' => 0,
  155. 'i18n_status' => 0,
  156. ],
  157. [
  158. 'lid' => 11,
  159. 'language' => 'fr',
  160. 'translation' => 'fr - description value 5',
  161. 'plid' => 0,
  162. 'plural' => 0,
  163. 'i18n_status' => 0,
  164. ]);
  165. // The expected results.
  166. array_push($tests[1]['expected_data'],
  167. [
  168. 'tid' => 3,
  169. 'vid' => 6,
  170. 'name' => 'name value 3',
  171. 'description' => 'description value 3',
  172. 'weight' => 0,
  173. 'is_container' => '',
  174. 'language' => 'zu',
  175. 'i18n_tsid' => '0',
  176. 'machine_name' => 'categories',
  177. 'tdlanguage' => 'und',
  178. 'lid' => '8',
  179. 'property' => 'name',
  180. 'ltlanguage' => 'zu',
  181. 'translation' => 'zu - name value 3',
  182. ],
  183. [
  184. 'tid' => 5,
  185. 'vid' => 6,
  186. 'name' => 'name value 5',
  187. 'description' => 'description value 5',
  188. 'weight' => 1,
  189. 'is_container' => '1',
  190. 'language' => 'fr',
  191. 'i18n_tsid' => '0',
  192. 'machine_name' => 'categories',
  193. 'tdlanguage' => 'und',
  194. 'lid' => '10',
  195. 'property' => 'name',
  196. 'ltlanguage' => 'fr',
  197. 'translation' => 'fr - name value 5',
  198. 'name_translated' => 'fr - name value 5',
  199. 'description_translated' => 'fr - description value 5',
  200. ],
  201. [
  202. 'tid' => 5,
  203. 'vid' => 6,
  204. 'name' => 'name value 5',
  205. 'description' => 'description value 5',
  206. 'weight' => 1,
  207. 'is_container' => '1',
  208. 'language' => 'fr',
  209. 'i18n_tsid' => '0',
  210. 'machine_name' => 'categories',
  211. 'tdlanguage' => 'und',
  212. 'lid' => '11',
  213. 'property' => 'description',
  214. 'ltlanguage' => 'fr',
  215. 'translation' => 'fr - description value 5',
  216. 'name_translated' => 'fr - name value 5',
  217. 'description_translated' => 'fr - description value 5',
  218. ]);
  219. $tests[1]['expected_count'] = NULL;
  220. // Empty configuration will return terms for all vocabularies.
  221. $tests[1]['configuration'] = [];
  222. return $tests;
  223. }
  224. }