PluralTranslationTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Drupal\Tests\Core\Annotation;
  3. use Drupal\Core\Annotation\PluralTranslation;
  4. use Drupal\Tests\UnitTestCase;
  5. /**
  6. * @coversDefaultClass \Drupal\Core\Annotation\PluralTranslation
  7. * @group Annotation
  8. */
  9. class PluralTranslationTest extends UnitTestCase {
  10. /**
  11. * @covers ::get
  12. *
  13. * @dataProvider providerTestGet
  14. */
  15. public function testGet(array $values) {
  16. $annotation = new PluralTranslation($values);
  17. $default_values = [
  18. 'context' => NULL,
  19. ];
  20. $this->assertEquals($values + $default_values, $annotation->get());
  21. }
  22. /**
  23. * Provides data to self::testGet().
  24. */
  25. public function providerTestGet() {
  26. $data = [];
  27. $data[] = [
  28. [
  29. 'singular' => $this->randomMachineName(),
  30. 'plural' => $this->randomMachineName(),
  31. 'context' => $this->randomMachineName(),
  32. ],
  33. ];
  34. $data[] = [
  35. [
  36. 'singular' => $this->randomMachineName(),
  37. 'plural' => $this->randomMachineName(),
  38. ],
  39. ];
  40. return $data;
  41. }
  42. /**
  43. * @dataProvider providerTestMissingData
  44. */
  45. public function testMissingData($data) {
  46. $this->expectException(\InvalidArgumentException::class);
  47. new PluralTranslation($data);
  48. }
  49. public function providerTestMissingData() {
  50. $data = [];
  51. $data['all-missing'] = [[]];
  52. $data['singular-missing'] = [['plural' => 'muh']];
  53. $data['plural-missing'] = [['singular' => 'muh']];
  54. return $data;
  55. }
  56. }