infoparser.php 1.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

/**
 * @author Thomas Müller
 * @copyright 2014 Thomas Müller deepdiver@owncloud.com
 * later.
 * See the COPYING-README file.
 */

namespace Test\App;

use OC;

class InfoParser extends \PHPUnit_Framework_TestCase {

	/**
	 * @var \OC\App\InfoParser
	 */
	private $parser;

	public function setUp() {
Thomas Müller's avatar
Thomas Müller committed
22
23
		$config = $this->getMockBuilder('\OC\AllConfig')
			->disableOriginalConstructor()->getMock();
24
		$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
Thomas Müller's avatar
Thomas Müller committed
25
26
			->setConstructorArgs(array($config))
			->setMethods(array('getHeaders'))
27
28
29
30
31
32
			->getMock();
		$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
			->disableOriginalConstructor()
			->getMock();

		//linkToDocs
Thomas Müller's avatar
Thomas Müller committed
33
		$urlGenerator->expects($this->any())
34
35
			->method('linkToDocs')
			->will($this->returnCallback(function ($url) {
Thomas Müller's avatar
Thomas Müller committed
36
				return "https://docs.example.com/server/go.php?to=$url";
37
38
39
40
41
			}));

		$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
	}

42
43
44
45
46
47
48
49
50
	/**
	 * @dataProvider providesInfoXml
	 */
	public function testParsingValidXml($expectedJson, $xmlFile) {
		$expectedData = null;
		if (!is_null($expectedJson)) {
			$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
		}
		$data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
51

Thomas Müller's avatar
Thomas Müller committed
52
		$this->assertEquals($expectedData, $data);
53
	}
Thomas Müller's avatar
Thomas Müller committed
54

55
56
57
58
59
60
	function providesInfoXml() {
		return array(
			array('expected-info.json', 'valid-info.xml'),
			array('strange-types-info.json', 'strange-types-info.xml'),
			array(null, 'invalid-info.xml'),
		);
Thomas Müller's avatar
Thomas Müller committed
61
	}
62
}