PhpDefaultCharsetTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Tests;
  8. use OCA\Settings\SetupChecks\PhpDefaultCharset;
  9. use OCP\IL10N;
  10. use OCP\SetupCheck\SetupResult;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. use Test\TestCase;
  13. class PhpDefaultCharsetTest extends TestCase {
  14. /** @var IL10N|MockObject */
  15. private $l10n;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->l10n = $this->getMockBuilder(IL10N::class)
  19. ->disableOriginalConstructor()->getMock();
  20. $this->l10n->expects($this->any())
  21. ->method('t')
  22. ->willReturnCallback(function ($message, array $replace) {
  23. return vsprintf($message, $replace);
  24. });
  25. }
  26. public function testPass(): void {
  27. $check = new PhpDefaultCharset($this->l10n);
  28. $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
  29. }
  30. public function testFail(): void {
  31. ini_set('default_charset', 'ISO-8859-15');
  32. $check = new PhpDefaultCharset($this->l10n);
  33. $this->assertEquals(SetupResult::WARNING, $check->run()->getSeverity());
  34. ini_restore('default_charset');
  35. }
  36. }