Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

74 lines
2.3KB

  1. <?php
  2. class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
  3. {
  4. /**
  5. * Protected reference of global factory we're testing.
  6. */
  7. protected $factory;
  8. public function setUp()
  9. {
  10. $this->factory = HTMLPurifier_LanguageFactory::instance();
  11. parent::setUp();
  12. }
  13. public function test()
  14. {
  15. $this->config->set('Core.Language', 'en');
  16. $language = $this->factory->create($this->config, $this->context);
  17. $this->assertIsA($language, 'HTMLPurifier_Language');
  18. $this->assertIdentical($language->code, 'en');
  19. // lazy loading test
  20. $this->assertIdentical(count($language->messages), 0);
  21. $language->load();
  22. $this->assertNotEqual(count($language->messages), 0);
  23. }
  24. public function testFallback()
  25. {
  26. $this->config->set('Core.Language', 'en-x-test');
  27. $language = $this->factory->create($this->config, $this->context);
  28. $this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
  29. $this->assertIdentical($language->code, 'en-x-test');
  30. $language->load();
  31. // test overloaded message
  32. $this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier X');
  33. // test inherited message
  34. $this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
  35. }
  36. public function testFallbackWithNoClass()
  37. {
  38. $this->config->set('Core.Language', 'en-x-testmini');
  39. $language = $this->factory->create($this->config, $this->context);
  40. $this->assertIsA($language, 'HTMLPurifier_Language');
  41. $this->assertIdentical($language->code, 'en-x-testmini');
  42. $language->load();
  43. $this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier XNone');
  44. $this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
  45. $this->assertIdentical($language->error, false);
  46. }
  47. public function testNoSuchLanguage()
  48. {
  49. $this->config->set('Core.Language', 'en-x-testnone');
  50. $language = $this->factory->create($this->config, $this->context);
  51. $this->assertIsA($language, 'HTMLPurifier_Language');
  52. $this->assertIdentical($language->code, 'en-x-testnone');
  53. $this->assertIdentical($language->error, true);
  54. }
  55. }
  56. // vim: et sw=4 sts=4