]> source.dussan.org Git - nextcloud-server.git/commitdiff
adding unit tests for OC_Util::basename
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 29 Jul 2013 21:32:03 +0000 (23:32 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 29 Jul 2013 21:32:03 +0000 (23:32 +0200)
lib/util.php
tests/lib/util.php

index 004470908d1289e33d3cd6b925729b989769cb5a..7f7b9f334b4646bd9d2084e7393ec96cc2f78f45 100755 (executable)
@@ -895,6 +895,7 @@ class OC_Util {
 
        public static function basename($file)
        {
+               $file = rtrim($file, '/');
                $t = explode('/', $file);
                return array_pop($t);
        }
index 9742d57ac7a9ba57d7783966d1b50bdece147908..2781ade09907b92a9be39b797bfd877dd194c195 100644 (file)
@@ -8,12 +8,9 @@
 
 class Test_Util extends PHPUnit_Framework_TestCase {
 
-       // Constructor
-       function Test_Util() {
+       function testFormatDate() {
                date_default_timezone_set("UTC");
-       }
 
-       function testFormatDate() {
                $result = OC_Util::formatDate(1350129205);
                $expected = 'October 13, 2012 11:53';
                $this->assertEquals($expected, $result);
@@ -61,8 +58,27 @@ class Test_Util extends PHPUnit_Framework_TestCase {
                OC_Config::deleteKey('mail_domain');
        }
 
-  function testGetInstanceIdGeneratesValidId() {
-    OC_Config::deleteKey('instanceid');
-    $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
-  }
+       function testGetInstanceIdGeneratesValidId() {
+               OC_Config::deleteKey('instanceid');
+               $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
+       }
+
+       /**
+        * @dataProvider baseNameProvider
+        */
+       public function testBaseName($expected, $file)
+       {
+               $base = \OC_Util::basename($file);
+               $this->assertEquals($expected, $base);
+       }
+
+       public function baseNameProvider()
+       {
+               return array(
+                       array('public_html', '/home/user/public_html/'),
+                       array('public_html', '/home/user/public_html'),
+                       array('', '/'),
+                       array('442aa682de2a64db1e010f50e60fd9c9', 'local::C:\Users\ADMINI~1\AppData\Local\Temp\2/442aa682de2a64db1e010f50e60fd9c9/')
+               );
+       }
 }