From b41f4cc64ea84a5e5102844b140635c4f6cadb2f Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Fri, 13 May 2016 22:43:59 +0200
Subject: [PATCH] LinkTest.php: two more exception tests ReportTest.php: Link,
 render mode, mailto

---
 extension/qfq/tests/phpunit/LinkTest.php   | 21 ++++++
 extension/qfq/tests/phpunit/ReportTest.php | 74 +++++++++++++++++++++-
 2 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/extension/qfq/tests/phpunit/LinkTest.php b/extension/qfq/tests/phpunit/LinkTest.php
index d036f21a1..1afa07637 100644
--- a/extension/qfq/tests/phpunit/LinkTest.php
+++ b/extension/qfq/tests/phpunit/LinkTest.php
@@ -645,6 +645,27 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-yellow.gif" title="yellow" > </a>', $result);
     }
 
+    /**
+     * @expectedException \qfq\UserReportException
+     */
+    public function testPictureException1() {
+        $link = new Link(null, $this->sip, true);
+
+        // r: default (0)
+        $result = $link->renderLink('u:http://www.example.com|P:picture.gif|B');
+    }
+
+    /**
+     * @expectedException \qfq\UserReportException
+     */
+    public function testPictureException2() {
+        $link = new Link(null, $this->sip, true);
+
+        // r: default (0)
+        $result = $link->renderLink('u:http://www.example.com|C|B');
+    }
+
+
     /**
      * @throws SyntaxReportException
      */
diff --git a/extension/qfq/tests/phpunit/ReportTest.php b/extension/qfq/tests/phpunit/ReportTest.php
index c661779b6..b2e0f324f 100644
--- a/extension/qfq/tests/phpunit/ReportTest.php
+++ b/extension/qfq/tests/phpunit/ReportTest.php
@@ -111,6 +111,78 @@ class ReportTest extends AbstractDatabaseTest {
         $this->assertEquals('1DoeSmithJohnJane2DoeSmithJohnJane', $result);
     }
 
+    /**
+     *
+     */
+    public function testReportLink() {
+
+        // link
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" class="external" >http://www.example.com</a>', $result);
+
+        // link, checked
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|C' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > </a>', $result);
+
+        // linck, checked, text
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|C|t:Hello World' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > Hello World</a>', $result);
+
+        // link, checked, text, tooltip
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|C|t:Hello World|o:more information' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" title="more information" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > Hello World</a>', $result);
+    }
+
+    /**
+     *
+     */
+    public function testReportLinkRenderMode() {
+
+        // r:0, url + text
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|t:Hello World|r:0' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" class="external" >Hello World</a>', $result);
+
+        // r:0, url
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|r:0' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" class="external" >http://www.example.com</a>', $result);
+
+        // r:0, text
+        $result = $this->report->process("10.sql = SELECT 'r:0|t:Hello World' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('', $result);
+
+        // r:1, url + text
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|t:Hello World|r:1' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" class="external" >Hello World</a>', $result);
+
+        // r:1, url
+        $result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|r:1' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="http://www.example.com" class="external" >http://www.example.com</a>', $result);
+
+        // r:1, text
+        $result = $this->report->process("10.sql = SELECT 'r:1|t:Hello World' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('Hello World', $result);
+
+    }
+
+    /**
+     *
+     */
+    public function testReportMailto() {
+
+        // r:0, mailto
+        $result = $this->report->process("10.sql = SELECT 'm:john.doe@example.com' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="mailto:john.doe@example.com" >mailto:john.doe@example.com</a>', $result);
+
+        $result = $this->report->process("10.sql = SELECT 'm:john.doe@example.com|e:0' AS _link FROM Person ORDER BY id LIMIT 1");
+        $this->assertEquals('<a href="mailto:john.doe@example.com" >mailto:john.doe@example.com</a>', $result);
+
+        //TODO: enable encryption check
+//        $result = $this->report->process("10.sql = SELECT 'm:john.doe@example.com|e:1' AS _link FROM Person ORDER BY id LIMIT 1");
+//        $this->assertEquals('<a href="mailto:john.doe@example.com" >mailto:john.doe@example.com</a>', $result);
+
+    }
+
+
     /**
      * @throws Exception
      */
@@ -123,10 +195,8 @@ class ReportTest extends AbstractDatabaseTest {
 
         $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
     }
-
 }
 
-
 class FakeTSFEReport {
     public $id = 1;
     public $type = 1;
-- 
GitLab