Exemplo n.º 1
0
 /**
  * Test saving code to template file
  */
 public function testSaveNonWriteable()
 {
     // If running as root you can always write, so this test should be
     // skipped when running as root.
     if (!ezcBaseFeatures::hasFunction("posix_getuid") || posix_getuid() == 0) {
         return;
     }
     copy($this->templatePath . "zhadum.ezt", $this->templateStorePath . "zhadum.ezt");
     // This only works on Linux/Unix, what to do here on other platforms?
     $old = umask(0);
     chmod($this->templateStorePath . "zhadum.ezt", 0444);
     umask($old);
     $src = new ezcTemplateSourceCode($this->templateStorePath . "zhadum.ezt", "planet:zhadum.ezt", "I would not go there if I were you.\nJust a friendly advice.\n");
     self::assertTrue(file_exists($this->templateStorePath . "zhadum.ezt"), 'Stored template file <' . $this->templateStorePath . 'zhadum.ezt> does not exist, cannot run save test.');
     self::assertTrue(!is_writeable($this->templateStorePath . "zhadum.ezt"), 'Stored template file <' . $this->templateStorePath . 'zhadum.ezt> should not be writable, cannot run save test.');
     try {
         $src->save();
         self::fail("No exception thrown for non-writeable file");
     } catch (ezcTemplateFileNotWriteableException $e) {
     }
     self::assertSame($this->templateStorePath . "zhadum.ezt", $src->stream, 'Property <stream> does not return correct value.');
     self::assertSame("planet:zhadum.ezt", $src->resource, 'Property <resource> does not return correct value.');
     self::assertSame("I would not go there if I were you.\nJust a friendly advice.\n", $src->code, 'Property <code> does not return correct value.');
     self::assertSame("A planet far far away.\n{\$planet.name}\n", file_get_contents($src->stream), 'Original file does no longer contain the correct value.');
     self::assertSame(true, file_exists($this->templateStorePath . "zhadum.ezt"), 'Stored template file <' . $this->templateStorePath . 'zhadum.ezt> does not exist after save()');
     self::assertSame("A planet far far away.\n{\$planet.name}\n", file_get_contents($this->templateStorePath . "zhadum.ezt"), 'File <' . $this->templateStorePath . 'zhadum.ezt> does not contain the original source code, file was probably written to (which should not happen).');
     //        self::assertSame( null, $src->context, 'Property <context> does not return correct value.' );
 }