Author: Tobias Schlitt
Date: 2006-01-24 16:41:20 +0100 (Tue, 24 Jan 2006)
New Revision: 2014

Log:
- Fix unreported bug that ezcCacheStorageFile::countDataItems() has wrong 
return value.
# Originally intended to return int, but returned bool.
- Fixed test cases accoringly.

Modified:
   packages/Cache/trunk/src/storage/file.php
   packages/Cache/trunk/tests/storage_file_test.php
   packages/Cache/trunk/tests/storage_test.php

Modified: packages/Cache/trunk/src/storage/file.php
===================================================================
--- packages/Cache/trunk/src/storage/file.php   2006-01-24 08:11:38 UTC (rev 
2013)
+++ packages/Cache/trunk/src/storage/file.php   2006-01-24 15:41:20 UTC (rev 
2014)
@@ -104,7 +104,7 @@
      */
     public function store( $id, $data, $attributes = array() ) 
     {
-        $filename = $this->generateIdentifier( $id, $attributes );
+        $filename = $this->location . $this->generateIdentifier( $id, 
$attributes );
         if ( file_exists( $filename ) ) 
         {
             if ( unlink( $filename ) === false ) 
@@ -156,7 +156,7 @@
      */
     public function restore( $id, $attributes = array() )
     {
-        $filename = $this->generateIdentifier( $id, $attributes );
+        $filename = $this->location . $this->generateIdentifier( $id, 
$attributes );
         if ( file_exists( $filename ) === false ) 
         {
             if ( count( $files = $this->search( $id, $attributes ) ) === 1 ) 
@@ -207,7 +207,7 @@
      */
     public function delete( $id = null, $attributes = array() )
     {
-        $filename = $this->generateIdentifier( $id, $attributes );
+        $filename = $this->location . $this->generateIdentifier( $id, 
$attributes );
         $delFiles = array();
         if ( file_exists( $filename ) ) 
         {
@@ -234,11 +234,11 @@
      * @param string $id                         The item ID.
      * @param array(string=>string) $attributes  Attributes describing the 
      *                                           data to restore.
-     * @return bool             If cache data with the specified criteria 
exists. 
+     * @return int Number of data items matching the criteria. 
      */
     public function countDataItems( $id = null, $attributes = array() )
     {
-        return ( count( $this->search( $id, $attributes ) ) > 0 );
+        return count( $this->search( $id, $attributes ) );
     }
 
     /**
@@ -272,8 +272,9 @@
      */
     private function search( $id = null, $attributes = array() )
     {
-        $glob = strtr( $this->generateIdentifier( $id, $attributes ), array( 
'-' => '*' ) ) . '*';
+        $glob = strtr( $this->generateIdentifier( $id, $attributes ), array( 
'-' => '*', '.' => '*' ) );
         $glob = ( isset( $id ) ? '*' : '' ) . $glob;
+        $glob = $this->location . $glob;
         return glob( $glob );
     }
 
@@ -348,6 +349,7 @@
             '-' => '#',
             ' ' => '%',
             ':' => '+',
+            '.' => '+',
         );
         if ( is_array( $attributes ) && count( $attributes ) > 0 ) 
         {
@@ -363,7 +365,7 @@
                 $filename .= $attrStr;
             }   
         }
-        return $this->location . $filename . $this->options['extension'];
+        return $filename . $this->options['extension'];
     }
 
     /**

Modified: packages/Cache/trunk/tests/storage_file_test.php
===================================================================
--- packages/Cache/trunk/tests/storage_file_test.php    2006-01-24 08:11:38 UTC 
(rev 2013)
+++ packages/Cache/trunk/tests/storage_file_test.php    2006-01-24 15:41:20 UTC 
(rev 2014)
@@ -21,21 +21,21 @@
     {
         $obj = new ezcCacheStorageFileArray( '/tmp' );
         $id = $obj->generateIdentifier( 
'contentstructuremenu/show_content_structure-2 file:foobar' );
-        $this->assertEquals( 
'/tmp/contentstructuremenu/show_content_structure-2_file:foobar.cache', $id );
+        $this->assertEquals( 
'contentstructuremenu/show_content_structure-2_file:foobar.cache', $id );
     }
 
     public function testGenerateIdentifier2()
     {
         $obj = new ezcCacheStorageFileArray( '/tmp' );
         $id = $obj->generateIdentifier( 
'contentstructuremenu\show_content_structure-2 file:foobar' );
-        $this->assertEquals( 
'/tmp/contentstructuremenu/show_content_structure-2_file:foobar.cache', $id );
+        $this->assertEquals( 
'contentstructuremenu/show_content_structure-2_file:foobar.cache', $id );
     }
 
     public function testGenerateIdentifier3()
     {
         $obj = new ezcCacheStorageFileArray( '/tmp', array( 'extension' => 
'.c' ) );
         $id = $obj->generateIdentifier( 
'contentstructuremenu\show_content_structure-2 file:foobar' );
-        $this->assertEquals( 
'/tmp/contentstructuremenu/show_content_structure-2_file:foobar.c', $id );
+        $this->assertEquals( 
'contentstructuremenu/show_content_structure-2_file:foobar.c', $id );
     }
 
     public function testInvalidConfigurationOption()

Modified: packages/Cache/trunk/tests/storage_test.php
===================================================================
--- packages/Cache/trunk/tests/storage_test.php 2006-01-24 08:11:38 UTC (rev 
2013)
+++ packages/Cache/trunk/tests/storage_test.php 2006-01-24 15:41:20 UTC (rev 
2014)
@@ -103,7 +103,7 @@
         foreach ( $this->data as $id => $dataArr ) 
         {
             $this->storage->store( $id, $dataArr );
-            $this->assertTrue( $this->storage->countDataItems( $id ), 'Storage 
file does not exist for ID: <' . $id . '>.' );
+            $this->assertEquals( $this->storage->countDataItems( $id ), 1, 
'Storage file does not exist for ID: <' . $id . '>.' );
         }
     }
 
@@ -119,10 +119,10 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             $this->storage->store( $id, $dataArr, $attributes );
-            $this->assertTrue( $this->storage->countDataItems( $id, 
$attributes ), 'Storage file does not exist for ID: <' . $id . '>.' );
+            $this->assertEquals( $this->storage->countDataItems( $id, 
$attributes ), 1, 'Storage file does not exist for ID: <' . $id . '>.' );
         }
     }
 
@@ -209,7 +209,7 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             $this->storage->store( $id, $dataArr, $attributes );
             $data = $this->storage->restore( $id, $attributes );
@@ -229,11 +229,11 @@
         foreach ( $this->data as $id => $dataArr ) 
         {
         
-            $filename = $this->storage->generateIdentifier( $id );
+            $filename = $this->storage->getLocation() . 
$this->storage->generateIdentifier( $id );
 
             $this->storage->store( $id, $dataArr );
             // Faking the m/a-time to be 100 seconds in the past
-            touch( $filename, ( time() - 100 ), ( time() - 100 ) );
+            touch( $filename, ( (string)microtime( true ) - 100 ), ( 
(string)microtime( true ) - 100 ) );
             
             // Wait for cache to be outdated.
             $data = $this->storage->restore( $id );
@@ -256,14 +256,14 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             
-            $filename = $this->storage->generateIdentifier( $id, $attributes );
+            $filename = $this->storage->getLocation() . 
$this->storage->generateIdentifier( $id, $attributes );
             
             $this->storage->store( $id, $dataArr, $attributes );
             // Faking the m/a-time to be 100 seconds in the past
-            touch( $filename, ( time() - 100 ), ( time() - 100 ) );
+            touch( $filename, ( (string)microtime( true ) - 100 ), ( 
(string)microtime( true ) - 100 ) );
            
             $data = $this->storage->restore( $id, $attributes );
             $this->assertTrue( $data === false, "Restore data broken for ID 
<{$id}>." );
@@ -282,11 +282,11 @@
         foreach ( $this->data as $id => $dataArr ) 
         {
             
-            $filename = $this->storage->generateIdentifier( $id );
+            $filename = $this->storage->getLocation() . 
$this->storage->generateIdentifier( $id );
 
             $this->storage->store( $id, $dataArr );
             // Faking the m/a-time to be 5 seconds in the past
-            touch( $filename, ( time() - 5 ), ( time() - 5 ) );
+            touch( $filename, ( (string)microtime( true ) - 5 ), ( 
(string)microtime( true ) - 5 ) );
             
             $data = $this->storage->restore( $id );
             $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
@@ -307,14 +307,14 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             
-            $filename = $this->storage->generateIdentifier( $id, $attributes );
+            $filename = $this->storage->getLocation() . 
$this->storage->generateIdentifier( $id, $attributes );
             
             $this->storage->store( $id, $dataArr, $attributes );
             // Faking the m/a-time to be 5 seconds in the past
-            touch( $filename, ( time() - 5 ), ( time() - 5 ) );
+            touch( $filename, ( (string)microtime( true ) - 5 ), ( 
(string)microtime( true ) - 5 ) );
             
             $data = $this->storage->restore( $id, $attributes );
             $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
@@ -349,7 +349,7 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             $this->storage->store( $id, $dataArr, $attributes );
             $this->storage->delete( $id, $attributes );
@@ -365,13 +365,13 @@
      */
     public function testStoreDeleteSuccessOnlyAttributes()
     {
+        $attributes = array(
+            'name'      => 'test',
+            'title'     => 'Test item',
+            'date'      => (string)microtime( true ),
+        );
         foreach ( $this->data as $id => $dataArr ) 
         {
-            $attributes = array(
-                'name'      => 'test',
-                'title'     => 'Test item',
-                'date'      => time(),
-            );
             $this->storage->store( $id, $dataArr, $attributes );
         }
         $this->storage->delete( null, $attributes );
@@ -408,7 +408,7 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ),
             );
             $this->storage->store( $id, $dataArr, $attributes );
             $this->assertTrue( $this->storage->countDataItems( $id, 
$attributes ) == 1, "countDataItems cannot find data for ID <{$id}>." );
@@ -427,7 +427,7 @@
             $attributes = array(
                 'name'      => 'test',
                 'title'     => 'Test item',
-                'date'      => time(),
+                'date'      => (string)microtime( true ).$id,
             );
             $this->storage->store( $id, $dataArr, $attributes );
             $this->assertTrue( $this->storage->countDataItems( null, 
$attributes ) == 1, "countDataItems cannot find data for ID <{$id}>." );

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to