function asu_webspark_bootstrap_settings_submit($form, &$form_state) { // Set the variables, need to use this instead of theme_get_settings // because the scop of the vars is more global. if ($form_state['values']['asu_brand_header_selector'] != 'custom') { variable_set('asu_brand_header_template', $form_state['values']['asu_brand_header_selector']); } else { variable_set('asu_brand_header_template', $form_state['values']['asu_brand_header_template']); } variable_set('asu_brand_is_student', $form_state['values']['asu_brand_is_student']); variable_set('asu_brand_student_color', $form_state['values']['asu_brand_student_color']); variable_set('asu_brand_header_selector', $form_state['values']['asu_brand_header_selector']); if ($file = $form_state['values']['picture_upload']) { unset($form_state['values']['picture_upload']); $filename = file_unmanaged_copy($file->uri); $form_state['values']['default_picture'] = 1; $form_state['values']['picture_path'] = $filename; } // If the user entered a path relative to the system files directory for // a logo or favicon, store a public:// URI so the theme system can handle it. if (!empty($form_state['values']['picture_path'])) { $form_state['values']['picture_path'] = _system_theme_settings_validate_path($form_state['values']['picture_path']); } // ASU header needs a cache_clear if (module_exists('asu_brand')) { asu_brand_cache_clear(); } }
/** * Contrast operations test. */ public function doTestContrastOperations() { $image_factory = $this->container->get('image.factory'); $image_toolkit_id = $image_factory->getToolkitId(); // Test on the PNG test image. $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test data. $test_data = ['0' => [$this->red, $this->green, $this->transparent, $this->blue], '-50' => [$image_toolkit_id === 'imagemagick' ? array(180, 75, 75, 0) : array(159, 95, 95, 0), $image_toolkit_id === 'imagemagick' ? array(75, 180, 75, 0) : array(95, 159, 95, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(75, 75, 180, 0) : array(95, 95, 159, 0)], '-100' => [$image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0)], '50' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)], '100' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)]]; foreach ($test_data as $key => $colors) { // Add contrast effect to the test image style. $effect = ['id' => 'image_effects_contrast', 'data' => ['level' => $key]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected contrast. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0))); $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19))); $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19))); // Remove effect. $uuid = $this->removeEffectFromTestStyle($uuid); } }
/** * Auto Orientation operations test. */ public function doTestAutoOrientOperations() { $image_factory = $this->container->get('image.factory'); $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_width' => 640, 'original_height' => 480, 'derivative_width' => 200, 'derivative_height' => 267], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_width' => 40, 'original_height' => 20, 'derivative_width' => 200, 'derivative_height' => 100], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_width' => 360, 'original_height' => 240, 'derivative_width' => 200, 'derivative_height' => 133]]; foreach ($test_data as $data) { // Get expected URIs. $original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test source image dimensions. $image = $image_factory->get($original_uri); $this->assertEqual($data['original_width'], $image->getWidth()); $this->assertEqual($data['original_height'], $image->getHeight()); // Load Image Style and get expected derivative URL. $image_style = ImageStyle::load('image_effects_test'); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); // Check that ::transformDimensions returns expected dimensions. $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="' . $data['derivative_width'] . '" height="' . $data['derivative_height'] . '" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected dimensions. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri); $this->assertEqual($data['derivative_width'], $image->getWidth()); $this->assertEqual($data['derivative_height'], $image->getHeight()); } }
/** * Watermark operations test. */ public function doTestWatermarkOperations() { $image_factory = $this->container->get('image.factory'); $test_file = drupal_get_path('module', 'simpletest') . '/files/image-1.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 1, 'y_offset' => 1, 'opacity' => 100, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected watermark. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $watermark = $image_factory->get($watermark_uri, 'gd'); $this->assertFalse($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 1, 1))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 1), $this->getPixelColor($image, 1, 2))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 3), $this->getPixelColor($image, 1, 4))); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test for watermark PNG image with full transparency set, 100% opacity // watermark. $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 100, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected transparency. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia)); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test for watermark PNG image with full transparency set, 50% opacity // watermark. $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 50, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected alpha. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia)); // GD and ImageMagick return slightly different colors, use the // ::colorsAreClose method. $this->assertTrue($this->colorsAreClose($this->getPixelColor($image, 39, 0), [127, 127, 127, 0])); // Remove effect. $this->removeEffectFromTestStyle($uuid); }
/** * Copy a file onto itself. */ function testOverwriteSelf() { // Create a file for testing $uri = $this->createUri(); // Copy the file onto itself with renaming works. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_RENAME); $this->assertTrue($new_filepath, 'Copying onto itself with renaming works.'); $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); $this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE)); // Copy the file onto itself without renaming fails. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_ERROR); $this->assertFalse($new_filepath, 'Copying onto itself without renaming fails.'); $this->assertTrue(file_exists($uri), 'File exists after copying onto itself.'); // Copy the file into same directory without renaming fails. $new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_ERROR); $this->assertFalse($new_filepath, 'Copying onto itself fails.'); $this->assertTrue(file_exists($uri), 'File exists after copying onto itself.'); // Copy the file into same directory with renaming works. $new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_RENAME); $this->assertTrue($new_filepath, 'Copying into same directory works.'); $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); $this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE)); }
/** * Submit handler */ function flux_theme_settings_submit($form, &$form_state) { $previous = theme_get_setting('cover_photo_path'); // If the user uploaded a new cover_photo or favicon, save it to a permanent location // and use it in place of the default theme-provided file. if (!empty($form_state['values']['cover_photo_upload'])) { $file = $form_state['values']['cover_photo_upload']; unset($form_state['values']['cover_photo_upload']); $filename = file_unmanaged_copy($file->uri, NULL, FILE_EXISTS_REPLACE); $form_state['values']['default_cover_photo'] = 0; $form_state['values']['cover_photo_path'] = $filename; $form_state['values']['toggle_cover_photo'] = 1; // Remove previous file uploaded $current = $form_state['values']['cover_photo_path']; if ($previous != $current && is_file($previous)) { // Delete previous file drupal_unlink($previous); } } // If the user entered a path relative to the system files directory for // a cover_photo or favicon, store a public:// URI so the theme system can handle it. if (!empty($form_state['values']['cover_photo_path'])) { $form_state['values']['cover_photo_path'] = flux_system_theme_settings_validate_path($form_state['values']['cover_photo_path']); } }
/** * Color Shift operations test. */ public function doTestColorshiftOperations() { $image_factory = $this->container->get('image.factory'); // Test on the PNG test image. $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test data. $test_data = ['#FF0000' => [$this->red, $this->yellow, $this->transparent, $this->fuchsia], '#00FF00' => [$this->yellow, $this->green, $this->transparent, $this->cyan], '#0000FF' => [$this->fuchsia, $this->cyan, $this->transparent, $this->blue], '#929BEF' => [[255, 155, 239, 0], [146, 255, 239, 0], $this->transparent, [146, 155, 255, 0]]]; foreach ($test_data as $key => $colors) { // Add Color Shift effect to the test image style. $effect = ['id' => 'image_effects_color_shift', 'data' => ['RGB][hex' => $key]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected color shift. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0))); $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19))); $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19))); // Remove effect. $uuid = $this->removeEffectFromTestStyle($uuid); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->adminUser); // Copy test po files to the translations directory. file_unmanaged_copy(__DIR__ . '/../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); file_unmanaged_copy(__DIR__ . '/../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->adminUser); // Copy test po files to the translations directory. file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE); }
/** * {@inheritdoc} */ function setUp() { parent::setUp(); $this->addLanguage('de'); $filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML')); $filtered_html_format->save(); $this->drupalCreateContentType(array('type' => 'test_bundle')); $this->loginAsAdmin(array('create translation jobs', 'submit translation jobs', 'create test_bundle content', $filtered_html_format->getPermissionName())); file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = File::create(array('uri' => 'public://example.jpg')); $this->image->save(); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Copy test po files to the translations directory. file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE); $this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->adminUser); // Enable import of translations. By default this is disabled for automated // tests. \Drupal::config('locale.settings')->set('translation.import_enabled', TRUE)->save(); }
/** * Set canvas operations test. */ public function doTestSetCanvasOperations() { $image_factory = $this->container->get('image.factory'); $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test EXACT size canvas. $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'exact', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FF00FF', 'canvas_color][container][opacity' => 100, 'exact][width' => '200%', 'exact][height' => '200%']]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::transformDimensions returns expected dimensions. $image = $image_factory->get($original_uri); $this->assertEqual(40, $image->getWidth()); $this->assertEqual(20, $image->getHeight()); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="80" height="40" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected canvas. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertEqual(80, $image->getWidth()); $this->assertEqual(40, $image->getHeight()); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 0))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 39))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 39))); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test RELATIVE size canvas. $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'relative', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FFFF00', 'canvas_color][container][opacity' => 100, 'relative][right' => 10, 'relative][left' => 20, 'relative][top' => 30, 'relative][bottom' => 40]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::transformDimensions returns expected dimensions. $image = $image_factory->get($original_uri); $this->assertEqual(40, $image->getWidth()); $this->assertEqual(20, $image->getHeight()); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="70" height="90" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected canvas. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertEqual(70, $image->getWidth()); $this->assertEqual(90, $image->getHeight()); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 0))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 89))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 89))); // Remove effect. $this->removeEffectFromTestStyle($uuid); }
/** * Given an image style, generate an image. */ function createSampleImage(ImageStyleInterface $style) { static $file_path; // First, we need to make sure we have an image in our testing // file directory. Copy over an image on the first run. if (!isset($file_path)) { $files = $this->drupalGetTestFiles('image'); $file = reset($files); $file_path = file_unmanaged_copy($file->uri); } return $style->buildUrl($file_path) ? $file_path : FALSE; }
/** * Tests removal of images having a non-local source. */ function testImageSource() { global $base_url; $public_files_path = PublicStream::basePath(); $http_base_url = preg_replace('/^https?/', 'http', $base_url); $https_base_url = preg_replace('/^https?/', 'https', $base_url); $files_path = base_path() . $public_files_path; $csrf_path = $public_files_path . '/' . implode('/', array_fill(0, substr_count($public_files_path, '/') + 1, '..')); $druplicon = 'core/misc/druplicon.png'; $red_x_image = base_path() . 'core/misc/icons/e32700/error.svg'; $alt_text = t('Image removed.'); $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.'); // Put a test image in the files directory. $test_images = $this->drupalGetTestFiles('image'); $test_image = $test_images[0]->filename; // Put a test image in the files directory with special filename. $special_filename = 'tést fïle nàme.png'; $special_image = rawurlencode($special_filename); $special_uri = str_replace($test_images[0]->filename, $special_filename, $test_images[0]->uri); file_unmanaged_copy($test_images[0]->uri, $special_uri); // Create a list of test image sources. // The keys become the value of the IMG 'src' attribute, the values are the // expected filter conversions. $host = \Drupal::request()->getHost(); $host_pattern = '|^http\\://' . $host . '(\\:[0-9]{0,5})|'; $images = array($http_base_url . '/' . $druplicon => base_path() . $druplicon, $https_base_url . '/' . $druplicon => base_path() . $druplicon, preg_replace($host_pattern, 'http://' . $host . ':', $http_base_url . '/' . $druplicon) => base_path() . $druplicon, preg_replace($host_pattern, 'http://' . $host . ':80', $http_base_url . '/' . $druplicon) => base_path() . $druplicon, preg_replace($host_pattern, 'http://' . $host . ':443', $http_base_url . '/' . $druplicon) => base_path() . $druplicon, preg_replace($host_pattern, 'http://' . $host . ':8080', $http_base_url . '/' . $druplicon) => base_path() . $druplicon, base_path() . $druplicon => base_path() . $druplicon, $files_path . '/' . $test_image => $files_path . '/' . $test_image, $http_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image, $https_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image, $http_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image, $https_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image, $files_path . '/example.png' => $red_x_image, 'http://example.com/' . $druplicon => $red_x_image, 'https://example.com/' . $druplicon => $red_x_image, 'javascript:druplicon.png' => $red_x_image, $csrf_path . '/logout' => $red_x_image); $comment = array(); foreach ($images as $image => $converted) { // Output the image source as plain text for debugging. $comment[] = $image . ':'; // Hash the image source in a custom test attribute, because it might // contain characters that confuse XPath. $comment[] = '<img src="' . $image . '" testattribute="' . hash('sha256', $image) . '" />'; } $edit = array('comment_body[0][value]' => implode("\n", $comment)); $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Save')); foreach ($images as $image => $converted) { $found = FALSE; foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) { $found = TRUE; if ($converted == $red_x_image) { $this->assertEqual((string) $element['src'], $red_x_image); $this->assertEqual((string) $element['alt'], $alt_text); $this->assertEqual((string) $element['title'], $title_text); $this->assertEqual((string) $element['height'], '16'); $this->assertEqual((string) $element['width'], '16'); } else { $this->assertEqual((string) $element['src'], $converted); } } $this->assertTrue($found, format_string('@image was found.', array('@image' => $image))); } }
/** * Tests using entity fields of the image field type. */ public function testImageItem() { // Create a test entity with the image field set. $entity = EntityTest::create(); $entity->image_test->target_id = $this->image->id(); $entity->image_test->alt = $alt = $this->randomMachineName(); $entity->image_test->title = $title = $this->randomMachineName(); $entity->name->value = $this->randomMachineName(); $entity->save(); $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->image_test->target_id, $this->image->id()); $this->assertEqual($entity->image_test->alt, $alt); $this->assertEqual($entity->image_test->title, $title); $image = $this->imageFactory->get('public://example.jpg'); $this->assertEqual($entity->image_test->width, $image->getWidth()); $this->assertEqual($entity->image_test->height, $image->getHeight()); $this->assertEqual($entity->image_test->entity->id(), $this->image->id()); $this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid()); // Make sure the computed entity reflects updates to the referenced file. file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg'); $image2 = File::create(['uri' => 'public://example-2.jpg']); $image2->save(); $entity->image_test->target_id = $image2->id(); $entity->image_test->alt = $new_alt = $this->randomMachineName(); // The width and height is only updated when width is not set. $entity->image_test->width = NULL; $entity->save(); $this->assertEqual($entity->image_test->entity->id(), $image2->id()); $this->assertEqual($entity->image_test->entity->getFileUri(), $image2->getFileUri()); $image = $this->imageFactory->get('public://example-2.jpg'); $this->assertEqual($entity->image_test->width, $image->getWidth()); $this->assertEqual($entity->image_test->height, $image->getHeight()); $this->assertEqual($entity->image_test->alt, $new_alt); // Check that the image item can be set to the referenced file directly. $entity->image_test = $this->image; $this->assertEqual($entity->image_test->target_id, $this->image->id()); // Delete the image and try to save the entity again. $this->image->delete(); $entity = EntityTest::create(array('mame' => $this->randomMachineName())); $entity->save(); // Test image item properties. $expected = array('target_id', 'entity', 'alt', 'title', 'width', 'height'); $properties = $entity->getFieldDefinition('image_test')->getFieldStorageDefinition()->getPropertyDefinitions(); $this->assertEqual(array_keys($properties), $expected); // Test the generateSampleValue() method. $entity = EntityTest::create(); $entity->image_test->generateSampleItems(); $this->entityValidateAndSave($entity); $this->assertEqual($entity->image_test->entity->get('filemime')->value, 'image/jpeg'); }
/** * {@inheritdoc} */ function setUp() { parent::setUp(); $this->langcode = 'de'; $this->context = 'default'; file_unmanaged_copy(drupal_get_path('module', 'tmgmt_locale') . '/tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); $file = new \stdClass(); $file->uri = \Drupal::service('file_system')->realpath(drupal_get_path('module', 'tmgmt_locale') . '/tests/test.xx.po'); $file->langcode = $this->langcode; Gettext::fileToDatabase($file, array()); $this->addLanguage($this->langcode); $this->addLanguage('gsw-berne'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Copy test po files to the translations directory. file_unmanaged_copy(__DIR__ . '/../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); file_unmanaged_copy(__DIR__ . '/../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE); $this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->adminUserAccessSiteReports = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'access site reports')); $this->drupalLogin($this->adminUser); // Enable import of translations. By default this is disabled for automated // tests. $this->config('locale.settings')->set('translation.import_enabled', TRUE)->save(); }
/** * Given an image style and a wrapper, generate an image. */ function createSampleImage($style, $wrapper) { static $file; if (!isset($file)) { $files = $this->drupalGetTestFiles('image'); $file = reset($files); } // Make sure we have an image in our wrapper testing file directory. $source_uri = file_unmanaged_copy($file->uri, $wrapper . '://'); // Build the derivative image. $derivative_uri = $style->buildUri($source_uri); $derivative = $style->createDerivative($source_uri, $derivative_uri); return $derivative ? $derivative_uri : FALSE; }
/** * {@inheritdoc} */ function setUp() { parent::setUp(); $this->langcode = 'de'; $this->context = 'default'; \Drupal::service('router.builder')->rebuild(); $this->installSchema('locale', array('locales_source', 'locales_target')); file_unmanaged_copy(drupal_get_path('module', 'tmgmt_locale') . '/tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); $file = new \stdClass(); $file->uri = \Drupal::service('file_system')->realpath(drupal_get_path('module', 'tmgmt_locale') . '/tests/test.xx.po'); $file->langcode = $this->langcode; Gettext::fileToDatabase($file, array()); $this->addLanguage('es'); }
/** * Saves a file for an entity and returns the file's ID. * * @param string $filename * The file name given by the user. * @param string $files_path * The file path where the file exists in. * * @return int * The file ID returned by the File::save() method. * * @throws \Exception * Throws an exception when the file is not found. */ public function createFile($filename, $files_path) { $path = rtrim(realpath($files_path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename; if (!is_file($path)) { throw new \Exception("File '{$filename}' was not found in file path '{$files_path}'."); } // Copy the file into the public files folder and turn it into a File // entity before linking it to the collection. $uri = 'public://' . $filename; $destination = file_unmanaged_copy($path, $uri); $file = File::create(['uri' => $destination]); $file->save(); $this->files[$file->id()] = $file; return $file->id(); }
/** * Tests using entity fields of the image field type. */ public function testImageItem() { // Create a test entity with the image field set. $entity = entity_create('entity_test'); $entity->image_test->target_id = $this->image->id(); $entity->image_test->alt = $alt = $this->randomMachineName(); $entity->image_test->title = $title = $this->randomMachineName(); $entity->name->value = $this->randomMachineName(); $entity->save(); $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->image_test->target_id, $this->image->id()); $this->assertEqual($entity->image_test->alt, $alt); $this->assertEqual($entity->image_test->title, $title); $image = $this->imageFactory->get('public://example.jpg'); $this->assertEqual($entity->image_test->width, $image->getWidth()); $this->assertEqual($entity->image_test->height, $image->getHeight()); $this->assertEqual($entity->image_test->entity->id(), $this->image->id()); $this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid()); // Make sure the computed entity reflects updates to the referenced file. file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/feed.png', 'public://example-2.jpg'); $image2 = entity_create('file', array('uri' => 'public://example-2.jpg')); $image2->save(); $entity->image_test->target_id = $image2->id(); $entity->image_test->alt = $new_alt = $this->randomMachineName(); // The width and height is only updated when width is not set. $entity->image_test->width = NULL; $entity->save(); $this->assertEqual($entity->image_test->entity->id(), $image2->id()); $this->assertEqual($entity->image_test->entity->getFileUri(), $image2->getFileUri()); $image = $this->imageFactory->get('public://example-2.jpg'); $this->assertEqual($entity->image_test->width, $image->getWidth()); $this->assertEqual($entity->image_test->height, $image->getHeight()); $this->assertEqual($entity->image_test->alt, $new_alt); // Check that the image item can be set to the referenced file directly. $entity->image_test = $this->image; $this->assertEqual($entity->image_test->target_id, $this->image->id()); // Delete the image and try to save the entity again. $this->image->delete(); $entity = entity_create('entity_test', array('mame' => $this->randomMachineName())); $entity->save(); // Test the generateSampleValue() method. $entity = entity_create('entity_test'); $entity->image_test->generateSampleItems(); $this->entityValidateAndSave($entity); }
/** * Test for transliteration of file name. */ public function testFileTransliteration() { $account = $this->drupalCreateUser(array('access site reports')); $this->drupalLogin($account); $original = drupal_get_path('module', 'simpletest') . '/files'; file_unmanaged_copy($original . '/image-1.png', PublicStream::basePath() . '/foo°.png'); // Upload with replace to guarantee there's something there. $edit = array('file_test_replace' => FILE_EXISTS_RENAME, 'files[file_test_upload]' => drupal_realpath('public://foo°.png')); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); $this->assertRaw(t('You WIN!'), 'Found the success message.'); $this->assertTrue(file_exists('temporary://foodeg.png')); $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $file = file_load($max_fid_after); $this->assertIdentical('foodeg.png', $file->getFilename()); $this->assertIdentical('temporary://foodeg.png', $file->getFileUri()); }
/** * Implements hook_form_FORM_ID_alter(). * * @param $form * The form. * @param $form_state * The form state. */ function adminimal_form_system_theme_settings_alter(&$form, &$form_state) { // Get adminimal theme path. global $base_url; $adminimal_path = drupal_get_path('theme', 'adminimal'); $old_css_path = $adminimal_path . '/css/custom.css'; $custom_css_path = 'public://adminimal-custom.css'; $custom_css_dir = str_replace($base_url . '/', "", file_create_url($custom_css_path)); $custom_css_url = file_create_url($custom_css_path); // Try to create the adminimal-custom.css file automatically. if (!file_exists($custom_css_path)) { // Try to migrate from the old css. if (file_exists($old_css_path)) { file_unmanaged_copy($old_css_path, $custom_css_path, FILE_EXISTS_ERROR); } else { file_unmanaged_save_data("", $custom_css_path, FILE_EXISTS_ERROR); } } // Notify user to remove his old css file. if (file_exists($old_css_path)) { drupal_set_message(t('Please delete the old @css_location file, as its no longer used.', array('@css_location file' => $old_css_path)), 'warning'); } $form['adminimal_custom'] = array('#type' => 'fieldset', '#title' => t('Adminimal Customization'), '#weight' => -10); $form['skin'] = array('#type' => 'fieldset', '#title' => t('Adminimal skin'), '#weight' => -11); // Create the select list. $form['skin']['adminimal_theme_skin'] = array('#type' => 'select', '#title' => t('Skin selection'), '#default_value' => theme_get_setting('adminimal_theme_skin'), '#options' => array('default' => t('Adminimal Default'), 'material' => t('Material (BETA version)'), 'alternative' => t('Alternative')), '#description' => t('Select desired skin style. Note that this feature is in beta stage and there might be some issues.'), '#required' => FALSE); $form['adminimal_custom']['style_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Style checkboxes and radio buttons in Webkit browsers.'), '#description' => t('Enabling this option will style checkbox and radio buttons for Webkit browsers like Google Chrome, Safari, Opera and their mobile versions. Enabling this option will <strong>not</strong> have any negative impact on older browsers that dont support pure CSS styling of checkboxes like Internet Explorer or Firefox.'), '#default_value' => theme_get_setting('style_checkboxes')); $form['adminimal_custom']['display_icons_config'] = array('#type' => 'checkbox', '#title' => t('Display icons in Configuration page'), '#default_value' => theme_get_setting('display_icons_config')); $form['adminimal_custom']['rounded_buttons'] = array('#type' => 'checkbox', '#title' => t('Use rounded buttons'), '#description' => t('Uncheck this setting if you dont like the rounded button styling for some action links'), '#default_value' => theme_get_setting('rounded_buttons')); $form['adminimal_custom']['sticky_actions'] = array('#type' => 'checkbox', '#title' => t('Sticky form actions'), '#description' => t('This will make the form actions div fixed bottom positioning. So for example when you visit the node edit page you wont need to scroll down to save/preview/delete the node. The form action buttons will be sticky to the bottom of the screen.'), '#default_value' => theme_get_setting('sticky_actions')); $form['adminimal_custom']['avoid_custom_font'] = array('#type' => 'checkbox', '#title' => t('Avoid using "Open Sans" font'), '#description' => t('(useful for languages that are not well supported by the "Open sans" font. Like Japanese for example)'), '#default_value' => theme_get_setting('avoid_custom_font')); $form['adminimal_custom']['adminimal_ckeditor'] = array('#type' => 'checkbox', '#title' => t('CKEditor support'), '#description' => t('Loads custom adminimal css skin for CKEditor. Disable this to avoid css conflicts when using other CKEditor skins.'), '#default_value' => theme_get_setting('adminimal_ckeditor')); $form['adminimal_custom']['use_custom_media_queries'] = array('#type' => 'checkbox', '#title' => t('Use Custom Media Queries'), '#description' => t('You can override the mobile and tablet media queries from this option. Use it only if you know what media queries are and how to use them.'), '#default_value' => theme_get_setting('use_custom_media_queries')); $form['adminimal_custom']['media_queries'] = array('#type' => 'fieldset', '#title' => t('Custom Media Queries'), '#states' => array('visible' => array(':input[name="use_custom_media_queries"]' => array('checked' => TRUE)))); $form['adminimal_custom']['media_queries']['media_query_mobile'] = array('#type' => 'textfield', '#title' => t('Mobile media query'), '#description' => t('The media query to load the mobile.css styles.'), '#default_value' => theme_get_setting('media_query_mobile')); $form['adminimal_custom']['media_queries']['media_query_tablet'] = array('#type' => 'textfield', '#title' => t('Tablet media query'), '#description' => t('The media query to load the tablet.css styles.'), '#default_value' => theme_get_setting('media_query_tablet')); $form['adminimal_custom']['custom_css'] = array('#type' => 'checkbox', '#title' => t('Use "adminimal-custom.css"'), '#description' => t('Include adminimal-custom.css file to override or add custom css code without subthememing/hacking Adminimal Theme.'), '#default_value' => theme_get_setting('custom_css')); $form['adminimal_custom']['adminimal_custom_check'] = array('#type' => 'fieldset', '#title' => t('Custom CSS file check'), '#weight' => 50, '#states' => array('visible' => array(':input[name="custom_css"]' => array('checked' => TRUE)))); if (file_exists($custom_css_path)) { $form['adminimal_custom']['adminimal_custom_check']['custom_css_description'] = array('#markup' => t('Custom CSS file Found in: !css', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")), '#prefix' => '<div class="messages status custom_css_found">', '#suffix' => '</div>'); } else { $form['adminimal_custom']['adminimal_custom_check']['custom_css_not_found'] = array('#markup' => t('Custom CSS file not found. You must create the !css file manually.', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")), '#prefix' => '<div class="messages error custom_css_not_found">', '#suffix' => '</div>'); } }
/** * Tests creating a content type during config import. */ public function testImportCreate() { $node_type_id = 'import'; $node_type_config_name = "node.type.{$node_type_id}"; // Simulate config data to import. $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); $this->copyConfig($active, $staging); // Manually add new node type. $src_dir = drupal_get_path('module', 'node_test_config') . '/staging'; $target_dir = $this->configDirectories[CONFIG_STAGING_DIRECTORY]; $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml")); // Import the content of the staging directory. $this->configImporter()->import(); // Check that the content type was created. $node_type = NodeType::load($node_type_id); $this->assertTrue($node_type, 'Import node type from staging was created.'); $this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body')); }
/** * Tests creating a content type during config import. */ public function testImportCreate() { $node_type_id = 'import'; $node_type_config_name = "node.type.{$node_type_id}"; // Simulate config data to import. $active = $this->container->get('config.storage'); $sync = $this->container->get('config.storage.sync'); $this->copyConfig($active, $sync); // Manually add new node type. $src_dir = __DIR__ . '/../../../modules/node_test_config/sync'; $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml")); // Import the content of the sync directory. $this->configImporter()->import(); // Check that the content type was created. $node_type = NodeType::load($node_type_id); $this->assertTrue($node_type, 'Import node type from sync was created.'); $this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body')); }
/** * Strip metadata operations test. */ public function doTestStripMetadataOperations() { $image_factory = $this->container->get('image.factory'); $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_orientation' => 8], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_orientation' => NULL], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_orientation' => NULL]]; foreach ($test_data as $data) { // Get expected URIs. $test_file = drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg'; $original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test source image EXIF data. $exif = @exif_read_data(\Drupal::service('file_system')->realpath($original_uri)); $this->assertEqual($data['original_orientation'], isset($exif['Orientation']) ? $exif['Orientation'] : NULL); // Load Image Style and process source image. $image_style = ImageStyle::load('image_effects_test'); $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); // Check that ::applyEffect strips EXIF metadata. $exif = @exif_read_data(\Drupal::service('file_system')->realpath($generated_uri)); $this->assertEqual(NULL, isset($exif['Orientation']) ? $exif['Orientation'] : NULL); } }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $source = $this->configuration['source_base_path'] . $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $replace = FILE_EXISTS_REPLACE; if (!empty($this->configuration['rename'])) { $entity_id = $row->getDestinationProperty($this->getKey('id')); if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) { $replace = FILE_EXISTS_RENAME; } } $dirname = drupal_dirname($destination); file_prepare_directory($dirname, FILE_CREATE_DIRECTORY); if ($this->configuration['move']) { file_unmanaged_move($source, $destination, $replace); } else { file_unmanaged_copy($source, $destination, $replace); } return parent::import($row, $old_destination_id_values); }
/** * Tests creating field storages and fields during config import. */ function testImportCreate() { // A field storage with one single field. $field_name = 'field_test_import_sync'; $field_storage_id = "entity_test.{$field_name}"; $field_id = "entity_test.entity_test.{$field_name}"; $field_storage_config_name = "field.storage.{$field_storage_id}"; $field_config_name = "field.field.{$field_id}"; // A field storage with two fields. $field_name_2 = 'field_test_import_sync_2'; $field_storage_id_2 = "entity_test.{$field_name_2}"; $field_id_2a = "entity_test.test_bundle.{$field_name_2}"; $field_id_2b = "entity_test.test_bundle_2.{$field_name_2}"; $field_storage_config_name_2 = "field.storage.{$field_storage_id_2}"; $field_config_name_2a = "field.field.{$field_id_2a}"; $field_config_name_2b = "field.field.{$field_id_2b}"; $active = $this->container->get('config.storage'); $sync = $this->container->get('config.storage.sync'); $this->copyConfig($active, $sync); // Add the new files to the sync directory. $src_dir = __DIR__ . '/../../modules/field_test_config/sync'; $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name}.yml", "{$target_dir}/{$field_storage_config_name}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name}.yml", "{$target_dir}/{$field_config_name}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name_2}.yml", "{$target_dir}/{$field_storage_config_name_2}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2a}.yml", "{$target_dir}/{$field_config_name_2a}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2b}.yml", "{$target_dir}/{$field_config_name_2b}.yml")); // Import the content of the sync directory. $this->configImporter()->import(); // Check that the field and storage were created. $field_storage = FieldStorageConfig::load($field_storage_id); $this->assertTrue($field_storage, 'Test import storage field from sync exists'); $field = FieldConfig::load($field_id); $this->assertTrue($field, 'Test import field from sync exists'); $field_storage = FieldStorageConfig::load($field_storage_id_2); $this->assertTrue($field_storage, 'Test import storage field 2 from sync exists'); $field = FieldConfig::load($field_id_2a); $this->assertTrue($field, 'Test import field 2a from sync exists'); $field = FieldConfig::load($field_id_2b); $this->assertTrue($field, 'Test import field 2b from sync exists'); }
/** * Test successful file reuse. */ public function testSuccessfulReuse() { $source_path = $this->root . '/core/modules/simpletest/files/image-test.jpg'; $destination_path = 'public://file1.jpg'; $file_reuse = file_unmanaged_copy($source_path, $destination_path); $timestamp = (new \SplFileInfo($file_reuse))->getMTime(); $this->assertInternalType('int', $timestamp); // We need to make sure the modified timestamp on the file is sooner than // the attempted migration. sleep(1); $configuration = ['reuse' => TRUE]; $this->doImport($source_path, $destination_path, $configuration); clearstatcache(TRUE, $destination_path); $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime(); $this->assertEquals($timestamp, $modified_timestamp); $configuration = ['reuse' => FALSE]; $this->doImport($source_path, $destination_path, $configuration); clearstatcache(TRUE, $destination_path); $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime(); $this->assertGreaterThan($timestamp, $modified_timestamp); }
/** * Test the resize feature. */ public function testResizeImages() { global $base_url; $druplicon = 'core/misc/druplicon.png'; $uri = file_unmanaged_copy($druplicon, 'public://druplicon.png', FILE_EXISTS_REPLACE); $file = File::create(['uri' => $uri, 'uuid' => 'thisisauuid']); $file->save(); $relative_path = str_replace($base_url, '', file_create_url($uri)); $images['inline-image'] = '<img alt="This is a description" data-entity-type="file" data-entity-uuid="' . $file->uuid() . '" height="50" src="' . $relative_path . '" width="44">'; $comment = []; foreach ($images as $key => $image) { $comment[$key] = $image; } $edit = array('comment_body[0][value]' => implode("\n", $comment)); $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Save')); $expected = 'public://resize/druplicon-44x50.png'; $expected_relative_path = str_replace($base_url, '', file_create_url($expected)); $this->assertNoRaw($relative_path, 'The original image is gone.'); $this->assertRaw($expected_relative_path, 'The resize version was found.'); $this->assertTrue(file_exists($expected), 'The resize file exists.'); }