aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/includes/FeedutilsTest.php
blob: d27df493997b132f6b5213edc7b13adfa10d8679 (plain) (blame)
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

namespace Zotlabs\Tests\Unit\includes;

use Zotlabs\Tests\Unit\UnitTestCase;

/**
 * @brief Unit Test case for include/feedutils.php file.
 */
class FeedutilsTest extends UnitTestCase {

	public function test_normalise_id() {
		$this->assertEquals('id', normalise_id('id'));
		$this->assertEquals('id', normalise_id('X-ZOT:id'));
		$this->assertEquals('id id2', normalise_id('X-ZOT:id X-ZOT:id2'));
		$this->assertEmpty(normalise_id(''));
	}

	public function test_encode_rel_links() {
		// invalid params return empty array
		$this->assertEquals([], encode_rel_links('string'));
		$this->assertEquals([], encode_rel_links([]));

		$b = ['attribs' => ['' => [
				'rel' => 'rel_value',
				'type' => 'type_value',
				'href' => 'href_value',
				'length' => 'length_value',
				'title' => 'title_value'
		]]];
		$blink1 = ['link1' => $b];
		$bresult[] = $b['attribs'][''];
		$this->assertEquals($bresult, encode_rel_links($blink1));
	}

/*	public function test_encode_rel_links_fail() {
		$a = [ 'key' => 'value'];
		$this->assertFalse(encode_rel_links($a));
		//Illegal string offset 'attribs'
	}*/

	/**
	 * @uses ::xmlify
	 */
	public function test_atom_author() {
		$this->assertEquals('', atom_author('', 'nick', 'name', 'uri', 72, 72, 'png', 'photourl'));

		$a = '<tag>
  <id>uri</id>
  <name>nick</name>
  <uri>uri</uri>
  <link rel="photo"  type="png" media:width="72" media:height="72" href="http://photourl" />
  <link rel="avatar" type="png" media:width="72" media:height="72" href="http://photourl" />
  <poco:preferredUsername>nick</poco:preferredUsername>
  <poco:displayName>name</poco:displayName>
</tag>';

		$this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl'));
	}
}