/**
  * Tests that set and get Modified files return the same.
  */
 public function test_set_and_get_modified_files_return_the_same()
 {
     $report = new Report\Report();
     $items = array('a' => 'b');
     $report->setModifiedFiles($items);
     $this->assertEquals($items, $report->getModifiedFiles());
 }
示例#2
0
 /**
  * Write the report to the filesystem so we can reuse it
  * at a later stace when we invoke Redbox\Scan\ScanService's scan() method.
  *
  * @param Report\Report|null $report
  * @return bool
  */
 public function write(Report\Report $report = null)
 {
     if ($report) {
         $data = $report->toArray();
         $data = Yaml::dump($data, 99);
         if (@file_put_contents($this->filename, $data) !== false) {
             /* I hate the @ with a passion with if we don't do it the tests will fail */
             return true;
         }
     }
     return false;
 }
示例#3
0
 /**
  * We need to test that toArray method on an instance of Redbox\Scan\Report\Report
  * returns a valid array.
  */
 public function test_report_to_array_returns_a_valid_array()
 {
     $input = array('name' => 'Test scan', 'date' => date(DATE_RFC2822), 'path' => '/somepath', 'items' => array());
     $report = Scan\Report\Report::fromArray($input);
     $output = $report->toArray();
     $this->assertEquals(json_encode($input), json_encode($output));
 }
示例#4
0
 /**
  * Return an instance of Report by providing an array to the method.
  *
  * @param array $array
  * @return Report
  */
 public static function fromArray($array = array())
 {
     $required = array('name', 'date', 'path', 'items');
     $report = new Report();
     /**
      * Check if all required fields are being set.
      */
     foreach ($required as $req) {
         if (isset($array[$req]) === false) {
             throw new Exception\RuntimeException('Could not create a report from this array field ' . $req . ' was not set the following fields are required (' . implode(',', $required) . ')');
         }
     }
     $report->setName($array['name']);
     $report->setDate($array['date']);
     $report->setPath($array['path']);
     $report->setItems($array['items']);
     return $report;
 }
 /**
  * Assert that writing to a local ftp server will fail if the user is not authenticated.
  */
 public function test_ftp_local_connection_file_write_fails()
 {
     if (($user = getenv('FTP_USER')) && ($pass = getenv('FTP_PASSWORD')) && ($host = getenv('FTP_HOST'))) {
         $ftp = new Adapter\Ftp('', '', '', 'httpdocs/scan_new.yml');
         $report = new Scan\Report\Report();
         $items = array('a' => 'b');
         $report->setItems($items);
         $result = $ftp->write($report);
         $this->assertFalse($result);
         unset($ftp);
     }
 }
示例#6
0
 /**
  * Write the report to the filesystem so we can reuse it
  * at a later stace when we invoke Redbox\Scan\ScanService's scan() method.
  *
  * @param Report|null $report
  * @return bool
  */
 public function write(Report $report = null)
 {
     if ($report) {
         $scandata = array('name' => $report->getName(), 'path' => $report->getPath());
         /* Step 1. Update the scan. */
         $sql = sprintf("UPDATE `scan` SET `name`='%s', `path`='%s', `scandate`=NOW()", $this->real_escape_string($scandata['name']), $this->real_escape_string($scandata['path']));
         $this->query($sql);
         if ($this->affected_rows > 0) {
             $items = $report->getItems();
             if (count($items) > 0) {
                 /* Step 2. Delete old items */
                 $sql = sprintf("DELETE FROM `scanitems` WHERE `scanid`='%s'", self::SCAN_ID);
                 $this->query($sql);
                 /* Step 3. Insert the new items */
                 foreach ($items as $path => $item) {
                     foreach ($item as $filename => $md5hash) {
                         $sql = sprintf("INSERT INTO `scanitems` SET `scanid`='%s', `itemfolder`='%s', `itemname`='%s', `md5hash`='%s'", self::SCAN_ID, $this->real_escape_string($path), $this->real_escape_string($filename), $this->real_escape_string($md5hash));
                         $this->query($sql);
                     }
                 }
             }
         }
         return false;
     }
     return false;
 }
 /**
  * Compare a write and read operation on the filesystem adapter.
  * Lets hope this passes.
  */
 public function test_filesystem_write_and_read_get_the_same_data()
 {
     $src_file = dirname(__FILE__) . '/Assets/Filesystem/data.yml';
     $target_file = dirname(__FILE__) . '/Assets/tmp/filesystem.yml';
     $local_data = Yaml::parse(@file_get_contents($src_file));
     /**
      * Read the source file and create a report from it.
      * We will write te file to a temp location and then read it
      * and compare the results.
      */
     $fs1 = new Scan\Adapter\Filesystem($target_file);
     $report1 = Scan\Report\Report::fromArray($local_data);
     $fs1->write($report1);
     /**
      * Read the test file and compare the results.
      */
     $fs2 = new Scan\Adapter\Filesystem($target_file);
     $report2 = $fs2->read();
     /**
      * Here go comparing the 2 results.
      */
     $this->assertEquals($report2->getName(), $report1->getName());
     $this->assertEquals($report2->getPath(), $report1->getPath());
     $this->assertEquals($report2->getDate(), $report1->getDate());
     $this->assertEquals(array(), $report1->getModifiedFiles());
     $this->assertEquals(array(), $report1->getNewfiles());
     unset($fs1);
     unset($fs2);
     unset($report1);
     unset($report2);
     unlink($target_file);
 }
示例#8
0
 /**
  * Write the report to the filesystem so we can reuse it
  * at a later stace when we invoke Redbox\Scan\ScanService's scan() method.
  *
  * @param Report\Report|null $report
  * @return bool
  */
 public function write(Report\Report $report = null)
 {
     if (!$this->handle) {
         return false;
     }
     if ($report) {
         $stream = fopen('php://memory', 'w+');
         if (!$stream) {
             return false;
         }
         $data = $report->toArray();
         $data = Yaml::dump($data, 99);
         fwrite($stream, $data);
         rewind($stream);
         if (ftp_fput($this->handle, $this->filename, $stream, $this->transfer_mode)) {
             return true;
         }
     }
     return false;
 }