aboutsummaryrefslogtreecommitdiffstats
path: root/autotest-checkers.sh
blob: cf810ce684ea429f42a989a5de9ae78e924fe6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
RESULT=0

bash ./build/autoloaderchecker.sh
RESULT=$(($RESULT+$?))
php ./build/translation-checker.php
RESULT=$(($RESULT+$?))
php ./build/triple-dot-checker.php
RESULT=$(($RESULT+$?))
php ./build/htaccess-checker.php
RESULT=$(($RESULT+$?))
php ./build/files-checker.php
RESULT=$(($RESULT+$?))

exit $RESULT
b; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace Test;

use JsonSerializable;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\InitialStateService;
use OCP\IServerContainer;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use stdClass;
use function json_encode;

class InitialStateServiceTest extends TestCase {
	/** @var InitialStateService */
	private $service;
	/** @var MockObject|LoggerInterface|(LoggerInterface&MockObject) */
	protected $logger;

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

		$this->logger = $this->createMock(LoggerInterface::class);

		$this->service = new InitialStateService(
			$this->logger,
			$this->createMock(Coordinator::class),
			$this->createMock(IServerContainer::class)
		);
	}

	public function staticData(): array {
		return [
			['string'],
			[23],
			[2.3],
			[new class implements JsonSerializable {
				public function jsonSerialize(): int {
					return 3;
				}
			}],
		];
	}

	/**
	 * @dataProvider staticData
	 */
	public function testStaticData(mixed $value): void {
		$this->service->provideInitialState('test', 'key', $value);
		$data = $this->service->getInitialStates();

		$this->assertEquals(
			['test-key' => json_encode($value)],
			$data
		);
	}

	public function testValidDataButFailsToJSONEncode(): void {
		$this->logger->expects($this->once())
			->method('error');

		$this->service->provideInitialState('test', 'key', ['upload' => INF]);
		$data = $this->service->getInitialStates();

		$this->assertEquals(
			[],
			$data
		);
	}

	public function testStaticButInvalidData(): void {
		$this->logger->expects($this->once())
			->method('warning');

		$this->service->provideInitialState('test', 'key', new stdClass());
		$data = $this->service->getInitialStates();

		$this->assertEquals(
			[],
			$data
		);
	}

	/**
	 * @dataProvider staticData
	 */
	public function testLazyData(mixed $value): void {
		$this->service->provideLazyInitialState('test', 'key', function () use ($value) {
			return $value;
		});
		$data = $this->service->getInitialStates();

		$this->assertEquals(
			['test-key' => json_encode($value)],
			$data
		);
	}
}