From d075fc8be661373f118830e2172c764c307c01b7 Mon Sep 17 00:00:00 2001
From: n0nag0n <n0nag0n@sky-9.com>
Date: Mon, 1 Jan 2024 18:05:34 -0700
Subject: [PATCH] 100% View class coverage

---
 flight/template/View.php |  5 +++--
 tests/ViewTest.php       | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/flight/template/View.php b/flight/template/View.php
index f4d866c..6796577 100644
--- a/flight/template/View.php
+++ b/flight/template/View.php
@@ -202,7 +202,8 @@ class View
      */
     public function e($str)
     {
-        echo htmlentities($str);
-        return htmlentities($str);
+		$value = htmlentities($str);
+        echo $value;
+        return $value;
     }
 }
diff --git a/tests/ViewTest.php b/tests/ViewTest.php
index 485a5bd..c952b50 100644
--- a/tests/ViewTest.php
+++ b/tests/ViewTest.php
@@ -33,6 +33,21 @@ class ViewTest extends PHPUnit\Framework\TestCase
         $this->assertNull($this->view->get('test'));
     }
 
+	public function testMultipleVariables() {
+		$this->view->set([
+			'test' => 123,
+			'foo' => 'bar'
+		]);
+
+		$this->assertEquals(123, $this->view->get('test'));
+		$this->assertEquals('bar', $this->view->get('foo'));
+
+		$this->view->clear();
+
+		$this->assertNull($this->view->get('test'));
+		$this->assertNull($this->view->get('foo'));
+	}
+
     // Check if template files exist
     public function testTemplateExists()
     {
@@ -48,6 +63,13 @@ class ViewTest extends PHPUnit\Framework\TestCase
         $this->expectOutputString('Hello, Bob!');
     }
 
+	public function testRenderBadFilePath() {
+		$this->expectException(Exception::class);
+		$this->expectExceptionMessage('Template file not found: '.__DIR__ . '/views/badfile.php');
+
+		$this->view->render('badfile');
+	}
+
     // Fetch template output
     public function testFetch()
     {
@@ -76,4 +98,22 @@ class ViewTest extends PHPUnit\Framework\TestCase
 
         $this->expectOutputString('Hello world, Bob!');
     }
+
+	public function testGetTemplateAbsolutePath() {
+		$tmpfile = tmpfile();
+		$file_path = stream_get_meta_data($tmpfile)['uri'].'.php';
+		$this->assertEquals($file_path, $this->view->getTemplate($file_path));
+	}
+
+	public function testE() {
+		$this->expectOutputString('&lt;script&gt;');
+		$result = $this->view->e('<script>');
+		$this->assertEquals('&lt;script&gt;', $result);
+	}
+
+	public function testENoNeedToEscape() {
+		$this->expectOutputString('script');
+		$result = $this->view->e('script');
+		$this->assertEquals('script', $result);
+	}
 }