Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InfoParserTest.php « App « lib « tests - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b72a869e02c63e786bf44f481273b05ce7e4c409 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
 * @author Thomas Müller
 * @copyright 2014 Thomas Müller deepdiver@owncloud.com
 * later.
 * See the COPYING-README file.
 */

namespace Test\App;

use OC;
use OC\App\InfoParser;
use Test\TestCase;

class InfoParserTest extends TestCase {
	/** @var OC\Cache\CappedMemoryCache */
	private static $cache;

	public static function setUpBeforeClass() {
		self::$cache = new OC\Cache\CappedMemoryCache();
	}


	public function parserTest($expectedJson, $xmlFile, $cache = null) {
		$parser = new InfoParser($cache);

		$expectedData = null;
		if (!is_null($expectedJson)) {
			$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
		}
		$data = $parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");

		$this->assertEquals($expectedData, $data);
	}

	/**
	 * @dataProvider providesInfoXml
	 */
	public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile) {
		$this->parserTest($expectedJson, $xmlFile);
	}

	/**
	 * @dataProvider providesInfoXml
	 */
	public function testParsingValidXmlWithCache($expectedJson, $xmlFile) {
		$this->parserTest($expectedJson, $xmlFile, self::$cache);
	}

	public function providesInfoXml(): array {
		return [
			['expected-info.json', 'valid-info.xml'],
			[null, 'invalid-info.xml'],
			['expected-info.json', 'valid-info.xml'],
			[null, 'invalid-info.xml'],
			['navigation-one-item.json', 'navigation-one-item.xml'],
			['navigation-two-items.json', 'navigation-two-items.xml'],
		];
	}
}