/**
  * Tests creating and setting access times of files with touch
  *
  * Tests wp_touch()
  */
 public function test_wp_touch()
 {
     $name = 'touch_test.txt';
     $uri = 'test://' . $name;
     $path = $this->test_dir . '/' . $name;
     /**
      * Test with URI
      */
     $this->assertTrue(wp_touch($uri));
     $this->assertFileExists($uri);
     $this->assertFileExists($path);
     unlink($path);
     $this->assertFileNotExists($uri);
     $this->assertFileNotExists($path);
     /**
      * Test with normal path
      */
     $this->assertTrue(wp_touch($path));
     $this->assertFileExists($path);
     $this->assertFileExists($uri);
     unlink($uri);
     $this->assertFileNotExists($path);
     $this->assertFileNotExists($uri);
     /**
      * Test a touch with a nonexistent directory
      */
     $uri = 'test://asdfasdf/' . $name;
     $this->assertFalse(wp_touch($uri));
     $this->assertFileNotExists($uri);
 }
 /**
  * Tests creating files, writing to files, and reading from files,
  * and deleting them again.
  *
  * Tests WP_Local_Stream_Wrapper_Base::fopen() and family
  */
 public function test_basic_file_manipulations()
 {
     /**
      * Test creating a file
      */
     $filename = 'testfile.txt';
     $uri = 'test://' . $filename;
     $path = $this->test_dir . '/' . $filename;
     $expected_contents = $this->sample_content;
     // Make sure the file doesn't exist to start with
     $this->assertFileNotExists($path);
     // Touch the file
     wp_touch($uri);
     $this->assertFileExists($path);
     // Unlink the file
     unlink($uri);
     $this->assertFileNotExists($path);
     // Open and write to the file
     $fh = fopen($uri, 'w');
     fwrite($fh, $expected_contents);
     fclose($fh);
     $this->assertFileExists($path);
     $this->assertEquals(filesize($uri), filesize($path));
     // Open and read from the file
     $fh = fopen($uri, 'r');
     $actual_contents = fread($fh, filesize($uri));
     fclose($fh);
     $this->assertEquals($expected_contents, $actual_contents);
     // Copy the file
     $second_filename = 'testfile2.txt';
     $second_uri = 'test://' . $second_filename;
     $second_path = $this->test_dir . '/' . $second_filename;
     copy($uri, $second_uri);
     $this->assertFileExists($this->test_dir . '/' . $second_filename);
     $this->assertEquals(filesize($uri), filesize($second_uri));
     // Unlink original file
     unlink($uri);
     $this->assertFileNotExists($path);
     // Rename second file to first file
     rename($second_uri, $uri);
     $this->assertFileNotExists($second_path);
     $this->assertfileExists($path);
     // Cleanup
     unlink($uri);
     $this->assertfileNotExists($path);
 }