aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
blob: 4fba60cf72f7d40fad4b9475fb57348193e13e07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Settings\Tests;

use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCP\IL10N;
use OCP\SetupCheck\SetupResult;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class PhpDefaultCharsetTest extends TestCase {
	/** @var IL10N|MockObject */
	private $l10n;

	protected function setUp(): void {
		parent::setUp();

		$this->l10n = $this->getMockBuilder(IL10N::class)
			->disableOriginalConstructor()->getMock();
		$this->l10n->expects($this->any())
			->method('t')
			->willReturnCallback(function ($message, array $replace) {
				return vsprintf($message, $replace);
			});
	}

	public function testPass(): void {
		$check = new PhpDefaultCharset($this->l10n);
		$this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
	}

	public function testFail(): void {
		ini_set('default_charset', 'ISO-8859-15');

		$check = new PhpDefaultCharset($this->l10n);
		$this->assertEquals(SetupResult::WARNING, $check->run()->getSeverity());

		ini_restore('default_charset');
	}
}