infoparser.php 1.2 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
42
			}));

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

	public function testParsingValidXml() {
Thomas Müller's avatar
Thomas Müller committed
43
		$expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true);
44
45
		$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml');

Thomas Müller's avatar
Thomas Müller committed
46
		$this->assertEquals($expectedData, $data);
47
48
	}
}