'Secure file tests', 'description' => 'Tests the saving of secure files.', 'group' => 'Configuration', ); } /** * Tests that a file written by this system has a valid signature. */ function testFileVerify() { $file = new SignedFileStorage($this->filename); $file->write($this->testContent); $this->assertTrue($file->verify(), 'A file verifies after being written.'); unset($file); // Load the file again, so that there is no stale data from the old object. $file = new SignedFileStorage($this->filename); $this->assertTrue($file->verify(), 'A file verifies after being written and reloaded.'); } /** * Tests that a file written by this system can be successfully read back. */ function testFilePersist() { $file = new SignedFileStorage($this->filename); $file->write($this->testContent); unset($file); // Reading should throw an exception in case of bad validation. // Note that if any other exception is thrown, we let the test system // handle catching and reporting it. try { $file = new SignedFileStorage($this->filename); $saved_content = $file->read(); $this->assertEqual($saved_content, $this->testContent, 'A file can be read back successfully.'); } catch (Exception $e) { $this->fail('File failed verification when being read.'); } } /** * Tests that a file fails validation if it's been monkeyed with. */ function testFileNotVerify() { $file = new SignedFileStorage($this->filename); $file->write($this->testContent); // Manually overwrite the body of the secure file. Note that we skip the // first line, which is reserved for the signature and such, to overwrite // just the payload. $raw_file = new SplFileObject($file->getFilePath(), 'a+'); $raw_file->fwrite('Good morning, Detroit!'); $raw_file->fflush(); unset($raw_file); unset($file); $file = new SignedFileStorage($this->filename); $this->assertFalse($file->verify(), 'Corrupted file does not verify.'); } } /** * Tests reading and writing file contents. */ class FileContentsTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Config file content tests', 'description' => 'Tests the reading and writing of config settings.', 'group' => 'Configuration', ); } /** * Tests that a simple setting can be written and read. */ public function testReadWriteConfig() { $config = config('foo.bar'); $config->set('foo', 'bar'); $config->save(); $this->assertEqual('bar', config('foo.bar')->get('foo'), 'Content retrived from written config data.'); } }