Example #1
0
 protected function setUp()
 {
     CMTest_TH::createLanguage();
     $this->_configInternalFile = new CM_File(DIR_ROOT . 'resources/config/js/internal.js');
     $this->_configInternalFile->ensureParentDirectory();
     $this->_configInternalFile->write('console.log("hello world")');
 }
Example #2
0
 /**
  * @param CM_File     $file
  * @param string|null $content
  * @param bool|null   $overwrite
  */
 public function createFile(CM_File $file, $content = null, $overwrite = null)
 {
     $parentDirectory = $file->getParentDirectory();
     if (!$parentDirectory->exists()) {
         $this->createDirectory($parentDirectory);
     }
     if ($file->exists()) {
         if (!$overwrite) {
             $this->notify('skip', $file->getPath());
         } else {
             $this->notify('modify', $file->getPath());
             $file->write($content);
         }
     } else {
         $this->notify('create', $file->getPath());
         $file->write($content);
     }
 }
Example #3
0
 /**
  * @param int|null $deployVersion
  */
 public function setDeployVersion($deployVersion = null)
 {
     $deployVersion = null !== $deployVersion ? (int) $deployVersion : time();
     $sourceCode = join(PHP_EOL, array('<?php', 'return function (CM_Config_Node $config) {', '    $config->deployVersion = ' . $deployVersion . ';', '};', ''));
     $targetPath = DIR_ROOT . 'resources/config/deploy.php';
     $configFile = new CM_File($targetPath);
     $configFile->ensureParentDirectory();
     $configFile->write($sourceCode);
 }
 /**
  * @param CM_File_Filesystem $filesystem
  */
 protected function _fillFilesystemWithRandomFiles(CM_File_Filesystem $filesystem)
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 20; $i++) {
         $directory = $faker->lexify('????????' . $i);
         for ($j = 0; $j < 10; $j++) {
             $path = $faker->lexify('????????' . $j);
             $content = $faker->paragraph(10);
             $file = new CM_File($directory . '/' . $path, $filesystem);
             $file->ensureParentDirectory();
             $file->write($content);
         }
     }
 }
Example #5
0
 public function testFetchDescriptionKeywordsConsiderNamespaceWideLocation()
 {
     $dirTmp = CM_Bootloader::getInstance()->getDirTmp();
     $render = $this->getMockBuilder('CM_Frontend_Render')->setMethods(array('getTemplatePath', 'getLayoutPath'))->getMock();
     $render->expects($this->any())->method('getTemplatePath')->will($this->returnValue(null));
     $render->expects($this->exactly(2))->method('getLayoutPath')->will($this->returnCallback(function ($templateName) use($dirTmp) {
         $templateFile = new CM_File($dirTmp . $templateName);
         $templateFile->ensureParentDirectory();
         $templateFile->write('test-' . $templateName);
         return $templateFile->getPath();
     }));
     /** @var CM_Frontend_Render $render */
     $page = $this->getMockBuilder('CM_Page_Abstract')->getMockForAbstractClass();
     /** @var CM_Page_Abstract $page */
     $renderAdapter = new CM_RenderAdapter_Page($render, $page);
     $this->assertSame('test-Page/Abstract/meta-description.tpl', $renderAdapter->fetchDescription());
     $this->assertSame('test-Page/Abstract/meta-keywords.tpl', $renderAdapter->fetchKeywords());
 }
Example #6
0
 public function testDeleteByPrefix()
 {
     $filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
     $dirTmp = CM_Bootloader::getInstance()->getDirTmp();
     $pathList = array('foo/foobar/bar', 'foo/bar2', 'foo/bar');
     /** @var CM_File[] $fileList */
     $fileList = array();
     foreach ($pathList as $path) {
         $file = new CM_File($dirTmp . $path, $filesystem);
         $file->ensureParentDirectory();
         $file->write('hello');
         $fileList[] = $file;
         $fileList[] = $file->getParentDirectory();
     }
     foreach ($fileList as $file) {
         $this->assertTrue($file->exists());
     }
     $filesystem->deleteByPrefix($dirTmp);
     foreach ($fileList as $file) {
         $this->assertFalse($file->exists());
     }
     $this->assertTrue((new CM_File($dirTmp))->exists());
 }
Example #7
0
 /**
  * @param CM_File $file
  */
 public function copyToFile(CM_File $file)
 {
     $sameFilesystemAdapter = $this->_filesystem->equals($file->_filesystem);
     if ($sameFilesystemAdapter) {
         $this->copy($file->getPath());
     } else {
         $file->write($this->read());
     }
 }
Example #8
0
 public function testListByPrefixDoNotFollowSymlinks()
 {
     $filesystem = new CM_File_Filesystem($this->_adapter);
     $file = new CM_File('foo/bar/foo', $filesystem);
     $file->ensureParentDirectory();
     $file->write('hello');
     symlink($filesystem->getAdapter()->getPathPrefix() . '/foo', $filesystem->getAdapter()->getPathPrefix() . '/link');
     $this->assertSame(array('files' => array('foo/bar/foo'), 'dirs' => array('foo/bar', 'foo', 'link')), $this->_adapter->listByPrefix(''));
 }
Example #9
0
 /**
  * @return string
  */
 protected function _getMachineId()
 {
     // Global machine-id from systemd https://www.freedesktop.org/software/systemd/man/machine-id.html
     $file = new CM_File('/etc/machine-id');
     if (!$file->exists()) {
         // Local machine-id as a backup
         $serviceManager = CM_Service_Manager::getInstance();
         $file = new CM_File('machine-id', $serviceManager->getFilesystems()->getData());
         if (!$file->exists()) {
             $uuid = Ramsey\Uuid\Uuid::uuid4()->toString();
             $file->write($uuid);
         }
     }
     return trim($file->read());
 }
 /**
  * @param S3Export_AwsBackupJob $job
  * @param S3Export_Device       $device
  */
 public function storeJobSignatureOnDevice(S3Export_AwsBackupJob $job, S3Export_Device $device)
 {
     $file = new CM_File('SIGNATURE', $device->getFilesystem());
     $file->write($job->getSignature());
 }