This file is indexed.

/usr/share/drupal6/modules/imagecache/tests/imagecache_create_url.test is in drupal6-mod-imagecache 2.0~beta10-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php // $Id: imagecache_create_url.test,v 1.4 2008/07/09 03:07:11 dopry Exp $

/**
 * Test class for testing imagecache_create_url() in several use cases with
 * the different combinations of clean URLs and private/public download method.
 */
class ImageCacheUrlTests extends DrupalTestCase {

  /**
   * General admin user.
   */
  var $admin_user;

  /**
   * The id of the php input format.
   */
  var $input_format_id;

  /**
   * Drupal SimpleTest method: return metadata about the test.
   */
  function get_info() {
     return array(
       'name' => 'ImageCache Create URL Tests',
       'desc' => 'Assure that URLs are properly generated by imagecache_create_url(), as discussed at http://drupal.org/node/241541',
       'group' => 'ImageCache',
     );
  }

  /**
   * SimpleTest core method: code run before each and every test method.
   */
  function setUp() {
    // Always call the setUp() function from the parent class.
    parent::setUp();

    // Make sure that the ImageCache module is enabled.
    $this->drupalModuleEnable('imagecache');

    // Create admin user
    $permissions = array(
      'administer filters',
    );
    $this->admin_user = $this->drupalCreateUserRolePerm($permissions);

    // Log in with admin user.
    $this->drupalLoginUser($this->admin_user);

    // Add an input format with PHP evaluator.
    $edit = array(
      'name' => $this->randomName(10, 'inputformat_'),
      'filters[filter/1]' => TRUE,
      'roles[2]' => TRUE,
    );
    $this->drupalPostRequest('admin/settings/filters/add', $edit, t('Save configuration'));
    // Store the format id of the created input format.
    $this->input_format_id = db_result(db_query("SELECT format FROM {filter_formats} WHERE name = '%s'", $edit['name']));
    $this->assertTrue($this->input_format_id, t('Input format id (%s)'));

  }

  /**
   * SimpleTest core method: code run after each and every test method.
   */
  function tearDown() {
    // Remove input format.
    $this->drupalPostRequest('admin/settings/filters/delete/'. $this->input_format_id, array(), t('Delete'));
    // Log out admin user.
    $this->drupalGet('logout');

    // Always call the tearDown() function from the parent class.
    parent::tearDown();
  }

  /**
   * Test function that tests imagecache_create_url() under
   * the different combinations of clean URLs and file download method
   */
  function testImageCacheCreateUrl() {
    // No Clean URLs + public downloads  : http://example.com/?q=path/to/files/imagecache/preset/foo.jpg
    $this->_ImagecacheCreateUrlTest(
      false, FILE_DOWNLOADS_PUBLIC,
      'path/to/files', 'preset', 'foo.jpg',
      'http://example.com/?q=path/to/files/imagecache/preset/foo.jpg'
    );

    // Clean URLs    + public downloads  : http://example.com/path/to/files/imagecache/preset/foo.jpg
    $this->_ImagecacheCreateUrlTest(
      true, FILE_DOWNLOADS_PUBLIC,
      'path/to/files', 'preset', 'foo.jpg',
      'http://example.com/path/to/files/imagecache/preset/foo.jpg'
    );

    // No Clean URLs + private downloads : http://example.com/?q=system/files/imagecache/preset/foo.jpg
    $this->_ImagecacheCreateUrlTest(
      false, FILE_DOWNLOADS_PRIVATE,
      'path/to/files', 'preset', 'foo.jpg',
      'http://example.com/?q=system/files/imagecache/preset/foo.jpg'
    );

    // Clean URLs    + private downloads : http://example.com/system/files/imagecache/preset/foo.jpg
    $this->_ImagecacheCreateUrlTest(
      true, FILE_DOWNLOADS_PRIVATE,
      'path/to/files', 'preset', 'foo.jpg',
      'http://example.com/system/files/imagecache/preset/foo.jpg'
    );
  }


  /**
   * Function to actually perform URL tests.
   * @param $clean_url
   *    'clean_url' setting for test.
   * @param $file_downloads
   *    'file_downloads' setting for test.
   * @param $file_directory_path
   *    'file_directory_path' setting for tests.
   * @param $preset
   *    imagecache preset name to be used for test.
   * @param $path
   *    file path to be used for generating output.
   * @param $expected
   *    the url expected as output from imagecache_create_url
   *
   * Note about the implementation:
   * At first sight one might think this can be easily implemented with just
   * setting the Drupal settings, calling imagecache_create_url() and checking
   * the result. This does not work however because the url() function, which is
   * used by imagecache_create_url(), caches the clean_url setting with an
   * internal static variable. This means that only one setting of clean_url
   * can be evaluated per page view.
   * To make testing possible, this function creates a node with the PHP
   * evaluator as input filter and puts a proper call to imagecache_create_url()
   * in the node body. The node view, which is a page view on its own can then
   * be checked for the correctly generated URL.
   */
  private function _ImagecacheCreateUrlTest($clean_url, $file_downloads, $file_directory_path, $preset, $path, $expected) {
    // Drupal settings
    $this->drupalVariableSet('clean_url', $clean_url);
    $this->drupalVariableSet('file_downloads', $file_downloads);
    $this->drupalVariableSet('file_directory_path', $file_directory_path);

    // Build node body (php code).
    $body = "<?php
      // Change base_url
      \$GLOBALS['base_url'] = 'http://example.com';
      // Generate URL and check it.
      echo imagecache_create_url('$preset', '$path');
      ?>";
    // Create node.
    $node = $this->drupalCreateNode(array(
      'body' => $body,
      'format' => $this->input_format_id,
    ));

    // Show node.
    $this->drupalGet(url('node/' . $node->nid, NULL, NULL, TRUE));

    // Check if expected url shows up
    $this->assertWantedRaw($expected,
      t('[ImageCacheUrlTests] @clean_url + @file_downloads should return "@expected"', array(
        '@clean_url' => ($clean_url ? 'Clean URLs' : 'No clean URLs'),
        '@file_downloads' => ($file_downloads == FILE_DOWNLOADS_PRIVATE ? 'private downloads' : 'public downloads'),
        '@expected' => $expected)
      )
    );
  }

}