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


PHP drupal_basename函数代码示例

本文整理汇总了PHP中drupal_basename函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_basename函数的具体用法?PHP drupal_basename怎么用?PHP drupal_basename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: testEditorEntityHooks

 /**
  * Tests the configurable text editor manager.
  */
 public function testEditorEntityHooks()
 {
     $image = entity_create('file');
     $image->setFileUri('core/misc/druplicon.png');
     $image->setFilename(drupal_basename($image->getFileUri()));
     $image->save();
     $file_usage = $this->container->get('file.usage');
     $this->assertIdentical(array(), $file_usage->listUsage($image), 'The image has zero usages.');
     $body_value = '<p>Hello, world!</p><img src="awesome-llama.jpg" data-entity-type="file" data-entity-uuid="' . $image->uuid() . '" />';
     // Test handling of an invalid data-entity-uuid attribute.
     $body_value .= '<img src="awesome-llama.jpg" data-entity-type="file" data-entity-uuid="invalid-entity-uuid-value" />';
     // Test handling of an invalid data-entity-type attribute.
     $body_value .= '<img src="awesome-llama.jpg" data-entity-type="invalid-entity-type-value" data-entity-uuid="' . $image->uuid() . '" />';
     // Test handling of a non-existing UUID.
     $body_value .= '<img src="awesome-llama.jpg" data-entity-type="file" data-entity-uuid="30aac704-ba2c-40fc-b609-9ed121aa90f4" />';
     // Test editor_entity_insert(): increment.
     $this->createUser();
     $node = entity_create('node', array('type' => 'page', 'title' => 'test', 'body' => array('value' => $body_value, 'format' => 'filtered_html'), 'uid' => 1));
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '1'))), $file_usage->listUsage($image), 'The image has 1 usage.');
     // Test editor_entity_update(): increment, twice, by creating new revisions.
     $node->setNewRevision(TRUE);
     $node->save();
     $second_revision_id = $node->getRevisionId();
     $node->setNewRevision(TRUE);
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image), 'The image has 3 usages.');
     // Test hook_entity_update(): decrement, by modifying the last revision:
     // remove the data-entity-type attribute from the body field.
     $body = $node->get('body')->first()->get('value');
     $original_value = $body->getValue();
     $new_value = str_replace('data-entity-type', 'data-entity-type-modified', $original_value);
     $body->setValue($new_value);
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image), 'The image has 2 usages.');
     // Test editor_entity_update(): increment again by creating a new revision:
     // read the data- attributes to the body field.
     $node->setNewRevision(TRUE);
     $node->get('body')->first()->get('value')->setValue($original_value);
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image), 'The image has 3 usages.');
     // Test hook_entity_update(): decrement, by modifying the last revision:
     // remove the data-entity-uuid attribute from the body field.
     $body = $node->get('body')->first()->get('value');
     $new_value = str_replace('data-entity-uuid', 'data-entity-uuid-modified', $original_value);
     $body->setValue($new_value);
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image), 'The image has 2 usages.');
     // Test hook_entity_update(): increment, by modifying the last revision:
     // read the data- attributes to the body field.
     $node->get('body')->first()->get('value')->setValue($original_value);
     $node->save();
     $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image), 'The image has 3 usages.');
     // Test editor_entity_revision_delete(): decrement, by deleting a revision.
     entity_revision_delete('node', $second_revision_id);
     $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image), 'The image has 2 usages.');
     // Test editor_entity_delete().
     $node->delete();
     $this->assertIdentical(array(), $file_usage->listUsage($image), 'The image has zero usages again.');
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:63,代码来源:EditorFileUsageTest.php

示例2: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = NULL, array $context = array())
 {
     $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody();
     $path = 'temporary://' . drupal_basename($data['uri'][0]['value']);
     $data['uri'] = file_unmanaged_save_data($file_data, $path);
     return $this->entityManager->getStorage('file')->create($data);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:FileEntityNormalizer.php

示例3: guess

 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     if ($this->mapping === NULL) {
         $mapping = $this->defaultMapping;
         // Allow modules to alter the default mapping.
         $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
         $this->mapping = $mapping;
     }
     $extension = '';
     $file_parts = explode('.', drupal_basename($path));
     // Remove the first part: a full filename should not match an extension.
     array_shift($file_parts);
     // Iterate over the file parts, trying to find a match.
     // For my.awesome.image.jpeg, we try:
     //   - jpeg
     //   - image.jpeg, and
     //   - awesome.image.jpeg
     while ($additional_part = array_pop($file_parts)) {
         $extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
         if (isset($this->mapping['extensions'][$extension])) {
             return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
         }
     }
     return 'application/octet-stream';
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:ExtensionMimeTypeGuesser.php

示例4: generateValues

 public function generateValues($object, $instance, $plugin_definition, $form_display_options)
 {
     static $file;
     $settings = $instance->getFieldSettings();
     if (empty($file)) {
         if ($path = $this->generateTextFile()) {
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? use case specific.
             $source->filemime = 'text/plain';
             $source->filename = drupal_basename($path);
             $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . '/' . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     }
     if (!$file) {
         // In case a previous file operation failed or no file is set, return FALSE
         return FALSE;
     } else {
         $object_field['target_id'] = $file->id();
         $object_field['display'] = $settings['display_default'];
         $object_field['description'] = DevelGenerateBase::createGreeking(10);
         return $object_field;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:DevelGenerateFieldFile.php

示例5: generateImage

 public function generateImage($object, $field, $instance, $bundle)
 {
     $object_field = array();
     static $available_images = array();
     if (empty($available_images)) {
         $available_images = $this->getImages();
     }
     if (empty($available_images)) {
         $args = func_get_args();
         return call_user_func_array('_image_devel_generate', $args);
     }
     $extension = array_rand(array('jpg' => 'jpg', 'png' => 'png'));
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     if (FALSE === ($tmp_file = drupal_tempnam('temporary://', 'imagefield_'))) {
         return FALSE;
     }
     $destination = $tmp_file . '.' . $extension;
     file_unmanaged_move($tmp_file, $destination, FILE_EXISTS_REPLACE);
     $rand_file = array_rand($available_images);
     if (!empty($instance['settings']['file_directory'])) {
         $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
     }
     $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
     file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
     if ($this->settings['devel_image_no_alter']) {
         $file = $available_images[$rand_file];
         $file = file_copy($file, $destination_dir);
     } else {
         $image = image_load($rand_file);
         $min = explode('x', $min_resolution);
         $max = explode('x', $max_resolution);
         $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
         $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
         $width = rand((int) $min[0], (int) $max[0]);
         $height = rand((int) $min[1], (int) $max[1]);
         if (!image_scale_and_crop($image, $width, $height)) {
             return FALSE;
         }
         // Use destination image type.
         $image->info['extension'] = $extension;
         if (!image_save($image, $destination)) {
             return FALSE;
         }
         $source = new stdClass();
         $source->uri = $destination;
         $source->uid = 1;
         // TODO: randomize? Use case specific.
         $source->filemime = $image->info['mime_type'];
         $source->filename = drupal_basename($image->source);
         $destination = $destination_dir . basename($destination);
         $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
开发者ID:kreynen,项目名称:elmsln,代码行数:58,代码来源:LocalFolderProvider.class.php

示例6: hook_favicon_file_uri_alter

/**
 * Alter the favicon file URI.
 *
 * @param string $uri
 *   A file URI.
 *
 * @see DrupalFavicon::getFileFromUri()
 */
function hook_favicon_file_uri_alter(&$uri)
{
    $basename = drupal_basename($uri);
    // Allow for individual user variations of the favicon file.
    $uri_with_uid = str_replace($basename, $basename . '-' . $GLOBALS['user']->uid, $uri);
    if (is_file($uri_with_uid)) {
        $uri = $uri_with_uid;
    }
}
开发者ID:kevintnguyens,项目名称:testsite,代码行数:17,代码来源:favicon.api.php

示例7: assertError

 /**
  * Asserts that a collected error matches what we are expecting.
  */
 function assertError($error, $group, $function, $file, $message = NULL)
 {
     $this->assertEqual($error['group'], $group, format_string("Group was %group", array('%group' => $group)));
     $this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", array('%function' => $function)));
     $this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", array('%file' => $file)));
     if (isset($message)) {
         $this->assertEqual($error['message'], $message, format_string("Message was %message", array('%message' => $message)));
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:12,代码来源:SimpleTestErrorCollectorTest.php

示例8: 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

示例9: validateFilePath

 /**
  * Validates a single file path.
  *
  * @param string $filepath
  *   The file path.
  *
  * @return bool
  *   Returns true if the file is valid, and false if not.
  */
 protected function validateFilePath($filepath)
 {
     $filename = drupal_basename($filepath);
     // Don't allow hidden files.
     if (substr($filename, 0, 1) === '.') {
         return FALSE;
     }
     // Validate file extension.
     $extension = substr($filename, strrpos($filename, '.') + 1);
     return in_array($extension, $this->configuration['allowed_extensions'], TRUE);
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:20,代码来源:DirectoryFetcher.php

示例10: testFileSaveData

 /**
  * Test the file_unmanaged_save_data() function.
  */
 function testFileSaveData()
 {
     $contents = $this->randomMachineName(8);
     $this->settingsSet('file_chmod_file', 0777);
     // No filename.
     $filepath = file_unmanaged_save_data($contents);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), "File was placed in Drupal's files directory.");
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     // Provide a filename.
     $filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.');
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     $this->assertFilePermissions($filepath, 0777);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:19,代码来源:UnmanagedSaveDataTest.php

示例11: testWithFilename

 /**
  * Test the file_save_data() function when a filename is provided.
  */
 function testWithFilename()
 {
     $contents = $this->randomName(8);
     // Using filename with non-latin characters.
     $filename = 'Текстовый файл.txt';
     $result = file_save_data($contents, 'public://' . $filename);
     $this->assertTrue($result, 'Unnamed file saved correctly.');
     $this->assertEqual('public', file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
     $this->assertEqual($filename, drupal_basename($result->getFileUri()), 'File was named correctly.');
     $this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
     $this->assertEqual($result->getMimeType(), 'text/plain', 'A MIME type was set.');
     $this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('insert'));
     // Verify that what was returned is what's in the database.
     $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:20,代码来源:SaveDataTest.php

示例12: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = NULL, array $context = array())
 {
     // File content can be passed base64 encoded in a special "data" property.
     // That property is not a field, so we remove it before denormalizing the
     // rest of the file entity.
     $file_data = $data['data'][0]['value'];
     unset($data['data']);
     $entity = parent::denormalize($data, $class, $format, $context);
     // Decode and save to file if it's a new file.
     if (!isset($context['request_method']) || $context['request_method'] != 'patch') {
         $file_contents = base64_decode($file_data);
         $dirname = $this->fileSystem->dirname($entity->getFileUri());
         file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
         if ($uri = file_unmanaged_save_data($file_contents, file_build_uri(drupal_basename($entity->getFilename())))) {
             $entity->setFileUri($uri);
         } else {
             throw new RuntimeException('failed to write ' . $entity->getFilename());
         }
     }
     return $entity;
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:24,代码来源:FileEntityNormalizer.php

示例13: generateValues

 function generateValues($object, $instance, $plugin_definition, $form_display_options)
 {
     $object_field = array();
     static $images = array();
     $settings = $instance->getSettings();
     $min_resolution = empty($settings['min_resolution']) ? '100x100' : $settings['min_resolution'];
     $max_resolution = empty($settings['max_resolution']) ? '600x600' : $settings['max_resolution'];
     $extensions = array_intersect(explode(' ', $settings['file_extensions']), array('png', 'gif', 'jpg', 'jpeg'));
     $extension = array_rand(array_combine($extensions, $extensions));
     // Generate a max of 5 different images.
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($path = $this->generateImage($extension, $min_resolution, $max_resolution)) {
             $account = user_load(1);
             $image = entity_create('file', array());
             $image->setFileUri($path);
             $image->setOwner($account);
             $image->setMimeType('image/' . pathinfo($path, PATHINFO_EXTENSION));
             $image->setFileName(drupal_basename($path));
             $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . '/' . basename($path);
             $file = file_move($image, $destination, FILE_CREATE_DIRECTORY);
             $images[$extension][$min_resolution][$max_resolution][$file->id()] = $file;
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $image_index = array_rand($images[$extension][$min_resolution][$max_resolution]);
         $file = $images[$extension][$min_resolution][$max_resolution][$image_index];
     }
     $object_field['target_id'] = $file->id();
     $object_field['alt'] = DevelGenerateBase::createGreeking(4);
     $object_field['title'] = DevelGenerateBase::createGreeking(4);
     return $object_field;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:36,代码来源:DevelGenerateFieldImage.php

示例14: testEditorEntityHooks

 /**
  * Tests the configurable text editor manager.
  */
 public function testEditorEntityHooks()
 {
     $image_paths = array(0 => 'core/misc/druplicon.png', 1 => 'core/misc/tree.png', 2 => 'core/misc/help.png');
     $image_entities = array();
     foreach ($image_paths as $key => $image_path) {
         $image = File::create();
         $image->setFileUri($image_path);
         $image->setFilename(drupal_basename($image->getFileUri()));
         $image->save();
         $file_usage = $this->container->get('file.usage');
         $this->assertIdentical(array(), $file_usage->listUsage($image), 'The image ' . $image_paths[$key] . ' has zero usages.');
         $image_entities[] = $image;
     }
     $body = array();
     foreach ($image_entities as $key => $image_entity) {
         // Don't be rude, say hello.
         $body_value = '<p>Hello, world!</p>';
         // Test handling of a valid image entry.
         $body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="' . $image_entity->uuid() . '" />';
         // Test handling of an invalid data-entity-uuid attribute.
         $body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="invalid-entity-uuid-value" />';
         // Test handling of an invalid data-entity-type attribute.
         $body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="invalid-entity-type-value" data-entity-uuid="' . $image_entity->uuid() . '" />';
         // Test handling of a non-existing UUID.
         $body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="30aac704-ba2c-40fc-b609-9ed121aa90f4" />';
         $body[] = array('value' => $body_value, 'format' => 'filtered_html');
     }
     // Test editor_entity_insert(): increment.
     $this->createUser();
     $node = $node = Node::create(['type' => 'page', 'title' => 'test', 'body' => $body, 'uid' => 1]);
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '1'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 1 usage.');
     }
     // Test editor_entity_update(): increment, twice, by creating new revisions.
     $node->setNewRevision(TRUE);
     $node->save();
     $second_revision_id = $node->getRevisionId();
     $node->setNewRevision(TRUE);
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
     }
     // Test hook_entity_update(): decrement, by modifying the last revision:
     // remove the data-entity-type attribute from the body field.
     $original_values = array();
     for ($i = 0; $i < count($image_entities); $i++) {
         $original_value = $node->body[$i]->value;
         $new_value = str_replace('data-entity-type', 'data-entity-type-modified', $original_value);
         $node->body[$i]->value = $new_value;
         $original_values[$i] = $original_value;
     }
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
     }
     // Test editor_entity_update(): increment again by creating a new revision:
     // read the data- attributes to the body field.
     $node->setNewRevision(TRUE);
     foreach ($original_values as $key => $original_value) {
         $node->body[$key]->value = $original_value;
     }
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
     }
     // Test hook_entity_update(): decrement, by modifying the last revision:
     // remove the data-entity-uuid attribute from the body field.
     foreach ($original_values as $key => $original_value) {
         $original_value = $node->body[$key]->value;
         $new_value = str_replace('data-entity-type', 'data-entity-type-modified', $original_value);
         $node->body[$key]->value = $new_value;
     }
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
     }
     // Test hook_entity_update(): increment, by modifying the last revision:
     // read the data- attributes to the body field.
     foreach ($original_values as $key => $original_value) {
         $node->body[$key]->value = $original_value;
     }
     $node->save();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
     }
     // Test editor_entity_revision_delete(): decrement, by deleting a revision.
     entity_revision_delete('node', $second_revision_id);
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
     }
     // Test editor_entity_delete().
     $node->delete();
     foreach ($image_entities as $key => $image_entity) {
         $this->assertIdentical(array(), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has zero usages again.');
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:100,代码来源:EditorFileUsageTest.php

示例15: testNormal

 /**
  * Test the file_save_upload() function.
  */
 function testNormal()
 {
     $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
     $this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
     $file1 = File::load($max_fid_after);
     $this->assertTrue($file1, 'Loaded the file.');
     // MIME type of the uploaded image may be either image/jpeg or image/png.
     $this->assertEqual(substr($file1->getMimeType(), 0, 5), 'image', 'A MIME type was set.');
     // Reset the hook counters to get rid of the 'load' we just called.
     file_test_reset();
     // Upload a second file.
     $image2 = current($this->drupalGetTestFiles('image'));
     $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri));
     $this->drupalPostForm('file-test/upload', $edit, t('Submit'));
     $this->assertResponse(200, 'Received a 200 response for posted test file.');
     $this->assertRaw(t('You WIN!'));
     $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('validate', 'insert'));
     $file2 = File::load($max_fid_after);
     $this->assertTrue($file2, 'Loaded the file');
     // MIME type of the uploaded image may be either image/jpeg or image/png.
     $this->assertEqual(substr($file2->getMimeType(), 0, 5), 'image', 'A MIME type was set.');
     // Load both files using File::loadMultiple().
     $files = File::loadMultiple(array($file1->id(), $file2->id()));
     $this->assertTrue(isset($files[$file1->id()]), 'File was loaded successfully');
     $this->assertTrue(isset($files[$file2->id()]), 'File was loaded successfully');
     // Upload a third file to a subdirectory.
     $image3 = current($this->drupalGetTestFiles('image'));
     $image3_realpath = drupal_realpath($image3->uri);
     $dir = $this->randomMachineName();
     $edit = array('files[file_test_upload]' => $image3_realpath, 'file_subdir' => $dir);
     $this->drupalPostForm('file-test/upload', $edit, t('Submit'));
     $this->assertResponse(200, 'Received a 200 response for posted test file.');
     $this->assertRaw(t('You WIN!'));
     $this->assertTrue(is_file('temporary://' . $dir . '/' . trim(drupal_basename($image3_realpath))));
 }
开发者ID:318io,项目名称:318-io,代码行数:40,代码来源:SaveUploadTest.php


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