ToolkitSetupFormTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\FunctionalTests\Image;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Tests image toolkit setup form.
  6. *
  7. * @group Image
  8. */
  9. class ToolkitSetupFormTest extends BrowserTestBase {
  10. /**
  11. * Admin user account.
  12. *
  13. * @var \Drupal\user\Entity\User
  14. */
  15. protected $adminUser;
  16. /**
  17. * Modules to enable.
  18. *
  19. * @var array
  20. */
  21. public static $modules = ['system', 'image_test'];
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected $defaultTheme = 'stark';
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function setUp() {
  30. parent::setUp();
  31. $this->adminUser = $this->drupalCreateUser([
  32. 'administer site configuration',
  33. ]);
  34. $this->drupalLogin($this->adminUser);
  35. }
  36. /**
  37. * Test Image toolkit setup form.
  38. */
  39. public function testToolkitSetupForm() {
  40. // Get form.
  41. $this->drupalGet('admin/config/media/image-toolkit');
  42. // Test that default toolkit is GD.
  43. $this->assertFieldByName('image_toolkit', 'gd', 'The default image toolkit is GD.');
  44. // Test changing the jpeg image quality.
  45. $edit = ['gd[image_jpeg_quality]' => '70'];
  46. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  47. $this->assertEqual($this->config('system.image.gd')->get('jpeg_quality'), '70');
  48. // Test changing the toolkit.
  49. $edit = ['image_toolkit' => 'test'];
  50. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  51. $this->assertEqual($this->config('system.image')->get('toolkit'), 'test');
  52. $this->assertFieldByName('test[test_parameter]', '10');
  53. // Test changing the test toolkit parameter.
  54. $edit = ['test[test_parameter]' => '0'];
  55. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  56. $this->assertText(t('Test parameter should be different from 0.'), 'Validation error displayed.');
  57. $edit = ['test[test_parameter]' => '20'];
  58. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  59. $this->assertEqual($this->config('system.image.test_toolkit')->get('test_parameter'), '20');
  60. // Test access without the permission 'administer site configuration'.
  61. $this->drupalLogin($this->drupalCreateUser(['access administration pages']));
  62. $this->drupalGet('admin/config/media/image-toolkit');
  63. $this->assertSession()->statusCodeEquals(403);
  64. }
  65. }