|
| 1 | +--TEST-- |
| 2 | +ResourceBundle::get() rejects fallback results when fallback is disabled with correct error message |
| 3 | +--EXTENSIONS-- |
| 4 | +intl |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require_once "resourcebundle.inc"; |
| 8 | + |
| 9 | +$fixture = __DIR__ . '/resourcebundle_get_without_fallback_tmp'; |
| 10 | +if (!is_dir($fixture)) { |
| 11 | + mkdir($fixture); |
| 12 | +} |
| 13 | +copy(BUNDLE . '/root.res', $fixture . '/root.res'); |
| 14 | + |
| 15 | +$resIndex = file_get_contents(BUNDLE . '/res_index.res'); |
| 16 | +$resIndex = str_replace("\0es\0root", "\0en\0root", $resIndex, $replacementCount); |
| 17 | +if ($replacementCount !== 1) { |
| 18 | + die("Failed to prepare resource bundle index\n"); |
| 19 | +} |
| 20 | +file_put_contents($fixture . '/res_index.res', $resIndex); |
| 21 | + |
| 22 | +// Keep the binary layout intact while making this key fall back to root.res. |
| 23 | +$enBundle = file_get_contents(BUNDLE . '/es.res'); |
| 24 | +$enBundle = str_replace('teststring', 'teststrinh', $enBundle, $replacementCount); |
| 25 | +if ($replacementCount !== 1) { |
| 26 | + die("Failed to prepare resource bundle fixture\n"); |
| 27 | +} |
| 28 | +file_put_contents($fixture . '/en.res', $enBundle); |
| 29 | + |
| 30 | +$bundle = new ResourceBundle('en', $fixture); |
| 31 | +echo debug($bundle->get('teststring', false)); |
| 32 | + |
| 33 | +$bundle = resourcebundle_create('en', $fixture); |
| 34 | +echo debug(resourcebundle_get($bundle, 'teststring', false)); |
| 35 | +?> |
| 36 | +--EXPECTF-- |
| 37 | +NULL |
| 38 | + %i: ResourceBundle::get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING |
| 39 | +NULL |
| 40 | + %i: resourcebundle_get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING |
| 41 | +--CLEAN-- |
| 42 | +<?php |
| 43 | +$fixture = __DIR__ . '/resourcebundle_get_without_fallback_tmp'; |
| 44 | +@unlink($fixture . '/en.res'); |
| 45 | +@unlink($fixture . '/root.res'); |
| 46 | +@unlink($fixture . '/res_index.res'); |
| 47 | +@rmdir($fixture); |
| 48 | +?> |
0 commit comments