LanguageFactoryTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. $this->factory = HTMLPurifier_LanguageFactory::instance();
  10. parent::setUp();
  11. }
  12. function test() {
  13. $this->config->set('Core.Language', 'en');
  14. $language = $this->factory->create($this->config, $this->context);
  15. $this->assertIsA($language, 'HTMLPurifier_Language');
  16. $this->assertIdentical($language->code, 'en');
  17. // lazy loading test
  18. $this->assertIdentical(count($language->messages), 0);
  19. $language->load();
  20. $this->assertNotEqual(count($language->messages), 0);
  21. }
  22. function testFallback() {
  23. $this->config->set('Core.Language', 'en-x-test');
  24. $language = $this->factory->create($this->config, $this->context);
  25. $this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
  26. $this->assertIdentical($language->code, 'en-x-test');
  27. $language->load();
  28. // test overloaded message
  29. $this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier X');
  30. // test inherited message
  31. $this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
  32. }
  33. function testFallbackWithNoClass() {
  34. $this->config->set('Core.Language', 'en-x-testmini');
  35. $language = $this->factory->create($this->config, $this->context);
  36. $this->assertIsA($language, 'HTMLPurifier_Language');
  37. $this->assertIdentical($language->code, 'en-x-testmini');
  38. $language->load();
  39. $this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier XNone');
  40. $this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
  41. $this->assertIdentical($language->error, false);
  42. }
  43. function testNoSuchLanguage() {
  44. $this->config->set('Core.Language', 'en-x-testnone');
  45. $language = $this->factory->create($this->config, $this->context);
  46. $this->assertIsA($language, 'HTMLPurifier_Language');
  47. $this->assertIdentical($language->code, 'en-x-testnone');
  48. $this->assertIdentical($language->error, true);
  49. }
  50. }
  51. // vim: et sw=4 sts=4