Browse Source

Adding initial PHPUnit tests and Travis conf

Alan Hardman 3 years ago
parent
commit
385b961b00
4 changed files with 88 additions and 0 deletions
  1. 8 0
      .travis.yml
  2. 7 0
      phpunit.xml
  3. 15 0
      tests/bootstrap.php
  4. 58 0
      tests/stringTest.php

+ 8 - 0
.travis.yml

@@ -0,0 +1,8 @@
+language: php
+php:
+  - '5.4'
+  - '5.5'
+  - '5.6'
+  - '7.0'
+  - hhvm
+  - nightly

+ 7 - 0
phpunit.xml

@@ -0,0 +1,7 @@
+<phpunit bootstrap="tests/bootstrap.php" colors="true">
+    <testsuites>
+        <testsuite name="All Tests">
+            <directory suffix="Test.php">tests/</directory>
+        </testsuite>
+    </testsuites>
+</phpunit>

+ 15 - 0
tests/bootstrap.php

@@ -0,0 +1,15 @@
+<?php
+set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__));
+$f3=require("lib/base.php");
+$f3->mset(array(
+	"UI" => "app/view/;app/plugin/",
+	"ESCAPE" => false,
+	"LOGS" => "log/",
+	"TEMP" => "tmp/",
+	"PREFIX" => "dict.",
+	"LOCALES" => "app/dict/",
+	"FALLBACK" => "en",
+	"CACHE" => false,
+	"AUTOLOAD" => "app/;lib/vendor/",
+	"PACKAGE" => "Phproject",
+));

+ 58 - 0
tests/stringTest.php

@@ -0,0 +1,58 @@
+<?php
+class StringTest extends PHPUnit_Framework_TestCase {
+
+	public function testRot8() {
+		$helper = \Helper\Security::instance();
+		$result = $helper->rot8("0af");
+		$this->assertEquals("827", $result);
+	}
+
+	public function testSalt() {
+		$helper = \Helper\Security::instance();
+		$result = $helper->salt();
+		$this->assertRegexp("/[0-9a-f]{32}/", $result);
+	}
+
+	public function testSaltSha1() {
+		$helper = \Helper\Security::instance();
+		$result = $helper->salt_sha1();
+		$this->assertRegexp("/[0-9a-f]{40}/", $result);
+	}
+
+	public function testHash() {
+		$helper = \Helper\Security::instance();
+		$string = "Hello world!";
+		$hash = $helper->hash($string);
+		$result = $helper->hash($string, $hash["salt"]);
+		$this->assertEquals($result, $hash["hash"]);
+	}
+
+	public function testFormatFilesize() {
+		$helper = \Helper\View::instance();
+		$size = 1288490189;
+		$result = $helper->formatFilesize($size);
+		$this->assertContains($result, array("1.2 GB", "1.20 GB"));
+	}
+
+	public function testGravatar() {
+		$helper = \Helper\View::instance();
+		$email = "alan@phpizza.com";
+		$result = $helper->gravatar($email);
+		$this->assertContains("gravatar.com/avatar/996df14", $result);
+	}
+
+	public function testUtc2local() {
+		$helper = \Helper\View::instance();
+
+		$tz = date_default_timezone_set("Etc/UTC");
+		\Base::instance()->set("site.timezone", "America/Phoenix");
+
+		$time = 1420498500;
+		$result = $helper->utc2local($time);
+
+		date_default_timezone_set($tz);
+
+		$this->assertEquals(1420473300, $result);
+	}
+
+}