aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2012-10-13 15:51:37 +0200
committerLukas Reschke <lukas@statuscode.ch>2012-10-13 15:51:40 +0200
commit0f26228d992e70d9c1f7acfe6e18bce1d02d4d4b (patch)
treeca015e10eb636823e612e1373f057de19462ebae /tests
parent95c8adba1936cf19d50d44555aaa40dbc447685a (diff)
downloadnextcloud-server-0f26228d992e70d9c1f7acfe6e18bce1d02d4d4b.tar.gz
nextcloud-server-0f26228d992e70d9c1f7acfe6e18bce1d02d4d4b.zip
Some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/helper.php144
1 files changed, 144 insertions, 0 deletions
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
new file mode 100644
index 00000000000..b12f8d929b7
--- /dev/null
+++ b/tests/lib/helper.php
@@ -0,0 +1,144 @@
+<?php
+/**
+ * Copyright (c) 2012 Lukas Reschke <lukas@statuscode.ch>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Helper extends UnitTestCase {
+ function testMakeURLAbsolute() {
+ $result = OC_Helper::makeURLAbsolute("/index.php?someParameter=value");
+ $expected = 'http://localhost/index.php?someParameter=value';
+ $this->assertEquals($result, $expected);
+ }
+
+ function testHumanFileSize() {
+ $result = OC_Helper::humanFileSize(0);
+ $expected = '0 B';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::humanFileSize(1024);
+ $expected = '1 kB';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::humanFileSize(10000000);
+ $expected = '9.5 MB';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::humanFileSize(500000000000);
+ $expected = '465.7 GB';
+ $this->assertEquals($result, $expected);
+ }
+
+ function testComputerFileSize() {
+ $result = OC_Helper::computerFileSize("0 B");
+ $expected = '0.0';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::computerFileSize("1 kB");
+ $expected = '1024.0';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::computerFileSize("9.5 MB");
+ $expected = '9961472.0';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::computerFileSize("465.7 GB");
+ $expected = '500041567436.8';
+ $this->assertEquals($result, $expected);
+ }
+
+ function testGetMimeType() {
+ $result = OC_Helper::getMimeType("./data/");
+ $expected = 'httpd/unix-directory';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::getMimeType("./data/data.tar.gz");
+ $expected = 'application/x-gzip';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::getMimeType("./data/data.zip");
+ $expected = 'application/zip';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::getMimeType("./data/logo-wide.svg");
+ $expected = 'image/svg+xml';
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::getMimeType("./data/logo-wide.png");
+ $expected = 'image/png';
+ $this->assertEquals($result, $expected);
+ }
+
+ function testGetStringMimeType() {
+ $result = OC_Helper::getStringMimeType("/data/data.tar.gz");
+ $expected = 'text/plain; charset=us-ascii';
+ $this->assertEquals($result, $expected);
+ }
+
+ function testIssubdirectory() {
+ $result = OC_Helper::issubdirectory("./data/", "/anotherDirectory/");
+ $this->assertFalse($result);
+
+ $result = OC_Helper::issubdirectory("./data/", "./data/");
+ $this->assertTrue($result);
+
+ mkdir("data/TestSubdirectory", 0777);
+ $result = OC_Helper::issubdirectory("data/TestSubdirectory/", "data");
+ rmdir("data/TestSubdirectory");
+ $this->assertTrue($result);
+ }
+
+ function testMb_array_change_key_case() {
+ $arrayStart = array(
+ "Foo" => "bar",
+ "Bar" => "foo",
+ );
+ $arrayResult = array(
+ "foo" => "bar",
+ "bar" => "foo",
+ );
+ $result = OC_Helper::mb_array_change_key_case($arrayStart);
+ $expected = $arrayResult;
+ $this->assertEquals($result, $expected);
+
+ $arrayStart = array(
+ "foo" => "bar",
+ "bar" => "foo",
+ );
+ $arrayResult = array(
+ "FOO" => "bar",
+ "BAR" => "foo",
+ );
+ $result = OC_Helper::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
+ $expected = $arrayResult;
+ $this->assertEquals($result, $expected);
+ }
+
+ function testMb_substr_replace() {
+ $result = OC_Helper::mb_substr_replace("This is a teststring", "string", 5);
+ $expected = "This string is a teststring";
+ $this->assertEquals($result, $expected);
+ }
+
+ function testMb_str_replace() {
+ $result = OC_Helper::mb_str_replace("teststring", "string", "This is a teststring");
+ $expected = "This is a string";
+ $this->assertEquals($result, $expected);
+ }
+
+ function testRecursiveArraySearch() {
+ $haystack = array(
+ "Foo" => "own",
+ "Bar" => "Cloud",
+ );
+
+ $result = OC_Helper::recursiveArraySearch($haystack, "own");
+ $expected = "Foo";
+ $this->assertEquals($result, $expected);
+
+ $result = OC_Helper::recursiveArraySearch($haystack, "NotFound");
+ $this->assertFalse($result);
+ }
+} \ No newline at end of file