aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/FeedBuilderTest.php14
-rw-r--r--tests/HttpUtils/GetIpAdressFromProxyTest.php58
-rw-r--r--tests/utils/ReferenceLinkDB.php6
3 files changed, 73 insertions, 5 deletions
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php
index 460fb0c5..c9ff397d 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/FeedBuilderTest.php
@@ -76,7 +76,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
76 // Test headers (RSS) 76 // Test headers (RSS)
77 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); 77 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
78 $this->assertEmpty($data['pubsubhub_url']); 78 $this->assertEmpty($data['pubsubhub_url']);
79 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $data['last_update']); 79 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']);
80 $this->assertEquals(true, $data['show_dates']); 80 $this->assertEquals(true, $data['show_dates']);
81 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); 81 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']);
82 $this->assertEquals('http://host.tld/', $data['index_url']); 82 $this->assertEquals('http://host.tld/', $data['index_url']);
@@ -88,7 +88,10 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
88 $this->assertEquals('20150310_114651', $link['linkdate']); 88 $this->assertEquals('20150310_114651', $link['linkdate']);
89 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 89 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['iso_date']); 91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
92 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
93 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
94 $this->assertEquals($pub, $up);
92 $this->assertContains('Stallman has a beard', $link['description']); 95 $this->assertContains('Stallman has a beard', $link['description']);
93 $this->assertContains('Permalink', $link['description']); 96 $this->assertContains('Permalink', $link['description']);
94 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 97 $this->assertContains('http://host.tld/?WDWyig', $link['description']);
@@ -101,6 +104,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
101 // Test multitags. 104 // Test multitags.
102 $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); 105 $this->assertEquals(5, count($data['links']['20141125_084734']['taglist']));
103 $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); 106 $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]);
107
108 // Test update date
109 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']);
104 } 110 }
105 111
106 /** 112 /**
@@ -112,8 +118,10 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
112 $feedBuilder->setLocale(self::$LOCALE); 118 $feedBuilder->setLocale(self::$LOCALE);
113 $data = $feedBuilder->buildData(); 119 $data = $feedBuilder->buildData();
114 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 120 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
121 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
115 $link = array_shift($data['links']); 122 $link = array_shift($data['links']);
116 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:+\d{2}/', $link['iso_date']); 123 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
124 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']);
117 } 125 }
118 126
119 /** 127 /**
diff --git a/tests/HttpUtils/GetIpAdressFromProxyTest.php b/tests/HttpUtils/GetIpAdressFromProxyTest.php
new file mode 100644
index 00000000..6a74a45a
--- /dev/null
+++ b/tests/HttpUtils/GetIpAdressFromProxyTest.php
@@ -0,0 +1,58 @@
1<?php
2
3require_once 'application/HttpUtils.php';
4
5/**
6 * Unitary tests for getIpAddressFromProxy()
7 */
8class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase {
9
10 /**
11 * Test without proxy
12 */
13 public function testWithoutProxy()
14 {
15 $this->assertFalse(getIpAddressFromProxy(array(), array()));
16 }
17
18 /**
19 * Test with a single IP in proxy header.
20 */
21 public function testWithOneForwardedIp()
22 {
23 $ip = '1.1.1.1';
24 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
25 $this->assertEquals($ip, getIpAddressFromProxy($server, array()));
26 }
27
28 /**
29 * Test with a multiple IPs in proxy header.
30 */
31 public function testWithMultipleForwardedIp()
32 {
33 $ip = '1.1.1.1';
34 $ip2 = '2.2.2.2';
35
36 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
37 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
38
39 $server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2);
40 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
41 }
42
43 /**
44 * Test with a trusted IP address.
45 */
46 public function testWithTrustedIp()
47 {
48 $ip = '1.1.1.1';
49 $ip2 = '2.2.2.2';
50
51 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
52 $this->assertFalse(getIpAddressFromProxy($server, array($ip)));
53
54 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
55 $this->assertEquals($ip2, getIpAddressFromProxy($server, array($ip)));
56 $this->assertFalse(getIpAddressFromProxy($server, array($ip, $ip2)));
57 }
58}
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index fcc7a4f9..937961c8 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -30,7 +30,8 @@ class ReferenceLinkDB
30 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', 30 'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
31 0, 31 0,
32 '20150310_114633', 32 '20150310_114633',
33 'free gnu software stallman -exclude stuff hashtag' 33 'free gnu software stallman -exclude stuff hashtag',
34 '20160803_093033'
34 ); 35 );
35 36
36 $this->addLink( 37 $this->addLink(
@@ -82,7 +83,7 @@ class ReferenceLinkDB
82 /** 83 /**
83 * Adds a new link 84 * Adds a new link
84 */ 85 */
85 protected function addLink($title, $url, $description, $private, $date, $tags) 86 protected function addLink($title, $url, $description, $private, $date, $tags, $updated = '')
86 { 87 {
87 $link = array( 88 $link = array(
88 'title' => $title, 89 'title' => $title,
@@ -91,6 +92,7 @@ class ReferenceLinkDB
91 'private' => $private, 92 'private' => $private,
92 'linkdate' => $date, 93 'linkdate' => $date,
93 'tags' => $tags, 94 'tags' => $tags,
95 'updated' => $updated,
94 ); 96 );
95 $this->_links[$date] = $link; 97 $this->_links[$date] = $link;
96 98