当前位置: 首页>>代码示例>>PHP>>正文


PHP File::setFileUri方法代码示例

本文整理汇总了PHP中Drupal\file\Entity\File::setFileUri方法的典型用法代码示例。如果您正苦于以下问题:PHP File::setFileUri方法的具体用法?PHP File::setFileUri怎么用?PHP File::setFileUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\file\Entity\File的用法示例。


在下文中一共展示了File::setFileUri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->image = entity_create('file');
     $this->image->setFileUri('core/misc/druplicon.png');
     $this->image->setFilename(drupal_basename($this->image->getFileUri()));
     $this->nonImage = entity_create('file');
     $this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js');
     $this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri()));
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:ValidatorTest.php

示例2: testFileValidateImageResolution

 /**
  *  This ensures the resolution of a specific file is within bounds.
  *  The image will be resized if it's too large.
  */
 function testFileValidateImageResolution()
 {
     // Non-images.
     $errors = file_validate_image_resolution($this->non_image);
     $this->assertEqual(count($errors), 0, 'Should not get any errors for a non-image file.', 'File');
     $errors = file_validate_image_resolution($this->non_image, '50x50', '100x100');
     $this->assertEqual(count($errors), 0, 'Do not check the resolution on non files.', 'File');
     // Minimum size.
     $errors = file_validate_image_resolution($this->image);
     $this->assertEqual(count($errors), 0, 'No errors for an image when there is no minimum or maximum resolution.', 'File');
     $errors = file_validate_image_resolution($this->image, 0, '200x1');
     $this->assertEqual(count($errors), 1, 'Got an error for an image that was not wide enough.', 'File');
     $errors = file_validate_image_resolution($this->image, 0, '1x200');
     $this->assertEqual(count($errors), 1, 'Got an error for an image that was not tall enough.', 'File');
     $errors = file_validate_image_resolution($this->image, 0, '200x200');
     $this->assertEqual(count($errors), 1, 'Small images report an error.', 'File');
     // Maximum size.
     if ($this->container->get('image.factory')->getToolkitId()) {
         // Copy the image so that the original doesn't get resized.
         copy('core/misc/druplicon.png', 'temporary://druplicon.png');
         $this->image->setFileUri('temporary://druplicon.png');
         $errors = file_validate_image_resolution($this->image, '10x5');
         $this->assertEqual(count($errors), 0, 'No errors should be reported when an oversized image can be scaled down.', 'File');
         $image = $this->container->get('image.factory')->get($this->image->getFileUri());
         $this->assertTrue($image->getWidth() <= 10, 'Image scaled to correct width.', 'File');
         $this->assertTrue($image->getHeight() <= 5, 'Image scaled to correct height.', 'File');
         // Once again, now with negative width and height to force an error.
         copy('core/misc/druplicon.png', 'temporary://druplicon.png');
         $this->image->setFileUri('temporary://druplicon.png');
         $errors = file_validate_image_resolution($this->image, '-10x-5');
         $this->assertEqual(count($errors), 1, 'An error reported for an oversized image that can not be scaled down.', 'File');
         drupal_unlink('temporary://druplicon.png');
     } else {
         // TODO: should check that the error is returned if no toolkit is available.
         $errors = file_validate_image_resolution($this->image, '5x10');
         $this->assertEqual(count($errors), 1, 'Oversize images that cannot be scaled get an error.', 'File');
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:42,代码来源:ValidatorTest.php


注:本文中的Drupal\file\Entity\File::setFileUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。