|
11 | 11 |
|
12 | 12 | use Framework\Language\FallbackLevel; |
13 | 13 | use Framework\Language\Language; |
| 14 | +use IntlListFormatter; |
14 | 15 | use PHPUnit\Framework\TestCase; |
15 | 16 |
|
16 | 17 | /** |
@@ -89,6 +90,65 @@ public function testDateWithInvalidStyle() : void |
89 | 90 | $this->language->date(\time(), 'unknown'); |
90 | 91 | } |
91 | 92 |
|
| 93 | + public function testList() : void |
| 94 | + { |
| 95 | + $strings = ['a', 'b', 'c']; |
| 96 | + $list = $this->language->list($strings); |
| 97 | + self::assertSame('a, b, and c', $list); |
| 98 | + $list = $this->language->list($strings, 'and'); |
| 99 | + self::assertSame('a, b, and c', $list); |
| 100 | + $list = $this->language->list($strings, IntlListFormatter::TYPE_OR); |
| 101 | + self::assertSame('a, b, or c', $list); |
| 102 | + $list = $this->language->list($strings, 'or'); |
| 103 | + self::assertSame('a, b, or c', $list); |
| 104 | + $list = $this->language->list($strings, IntlListFormatter::TYPE_UNITS); |
| 105 | + self::assertSame('a, b, c', $list); |
| 106 | + $list = $this->language->list($strings, 'units'); |
| 107 | + self::assertSame('a, b, c', $list); |
| 108 | + $list = $this->language->list($strings, locale: 'en_US'); |
| 109 | + self::assertSame('a, b, and c', $list); |
| 110 | + $list = $this->language->list($strings, width: 'wide', locale: 'en_US'); |
| 111 | + self::assertSame('a, b, and c', $list); |
| 112 | + $list = $this->language->list($strings, width: IntlListFormatter::WIDTH_SHORT, locale: 'en_US'); |
| 113 | + self::assertSame('a, b, & c', $list); |
| 114 | + $list = $this->language->list($strings, width: 'short', locale: 'en_US'); |
| 115 | + self::assertSame('a, b, & c', $list); |
| 116 | + $list = $this->language->list($strings, width: IntlListFormatter::WIDTH_NARROW, locale: 'en_US'); |
| 117 | + self::assertSame('a, b, c', $list); |
| 118 | + $list = $this->language->list($strings, width: 'narrow', locale: 'en_US'); |
| 119 | + self::assertSame('a, b, c', $list); |
| 120 | + $list = $this->language->list($strings, locale: 'DE'); |
| 121 | + self::assertSame('a, b und c', $list); |
| 122 | + $list = $this->language->list($strings, locale: 'pt-Br'); |
| 123 | + self::assertSame('a, b e c', $list); |
| 124 | + } |
| 125 | + |
| 126 | + public function testListWithInvalidLocale() : void |
| 127 | + { |
| 128 | + $strings = ['a', 'b', 'c']; |
| 129 | + $this->expectException(\ValueError::class); |
| 130 | + $this->expectExceptionMessage( |
| 131 | + 'IntlListFormatter::__construct(): Argument #1 ($locale) "foo" is invalid' |
| 132 | + ); |
| 133 | + $this->language->list($strings, locale: 'foo'); |
| 134 | + } |
| 135 | + |
| 136 | + public function testListWithInvalidType() : void |
| 137 | + { |
| 138 | + $strings = ['a', 'b', 'c']; |
| 139 | + $this->expectException(\InvalidArgumentException::class); |
| 140 | + $this->expectExceptionMessage('Invalid list type: foo'); |
| 141 | + $this->language->list($strings, type: 'foo'); |
| 142 | + } |
| 143 | + |
| 144 | + public function testListWithInvalidWidth() : void |
| 145 | + { |
| 146 | + $strings = ['a', 'b', 'c']; |
| 147 | + $this->expectException(\InvalidArgumentException::class); |
| 148 | + $this->expectExceptionMessage('Invalid list width: foo'); |
| 149 | + $this->language->list($strings, width: 'foo'); |
| 150 | + } |
| 151 | + |
92 | 152 | public function testDirectories() : void |
93 | 153 | { |
94 | 154 | self::assertSame([ |
|
0 commit comments