@@ -40,6 +40,48 @@ public function testFileWithTrailingSlash()
4040 $ this ->getSetDelete ($ cache );
4141 }
4242
43+ public function testFileDirectoryPermissions ()
44+ {
45+ $ dir = sys_get_temp_dir () . '/google-api-php-client/tests/ ' . rand ();
46+ $ cache = new Google_Cache_File ($ dir );
47+ $ cache ->set ('foo ' , 'bar ' );
48+
49+ $ method = new ReflectionMethod ($ cache , 'getWriteableCacheFile ' );
50+ $ method ->setAccessible (true );
51+ $ filename = $ method ->invoke ($ cache , 'foo ' );
52+ $ stat = stat ($ dir );
53+
54+ $ this ->assertEquals (0777 & ~umask (), $ stat ['mode ' ] & 0777 );
55+ }
56+
57+ public function testFileWithDefaultMask ()
58+ {
59+ $ dir = sys_get_temp_dir () . '/google-api-php-client/tests/ ' ;
60+ $ cache = new Google_Cache_File ($ dir );
61+ $ cache ->set ('foo ' , 'bar ' );
62+
63+ $ method = new ReflectionMethod ($ cache , 'getWriteableCacheFile ' );
64+ $ method ->setAccessible (true );
65+ $ filename = $ method ->invoke ($ cache , 'foo ' );
66+ $ stat = stat ($ filename );
67+
68+ $ this ->assertEquals (0666 & ~umask (), $ stat ['mode ' ] & 0777 );
69+ }
70+
71+ public function testFileWithCustomMask ()
72+ {
73+ $ dir = sys_get_temp_dir () . '/google-api-php-client/tests/ ' ;
74+ $ cache = new Google_Cache_File ($ dir , null );
75+ $ cache ->set ('foo ' , 'bar ' );
76+
77+ $ method = new ReflectionMethod ($ cache , 'getWriteableCacheFile ' );
78+ $ method ->setAccessible (true );
79+ $ filename = $ method ->invoke ($ cache , 'foo ' );
80+ $ stat = stat ($ filename );
81+
82+ $ this ->assertEquals (0666 & ~umask (), $ stat ['mode ' ] & 0777 );
83+ }
84+
4385 public function testNull ()
4486 {
4587 $ cache = new Google_Cache_Null ();
0 commit comments