ToolkitSetupFormTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 function setUp() {
  26. parent::setUp();
  27. $this->adminUser = $this->drupalCreateUser([
  28. 'administer site configuration',
  29. ]);
  30. $this->drupalLogin($this->adminUser);
  31. }
  32. /**
  33. * Test Image toolkit setup form.
  34. */
  35. public function testToolkitSetupForm() {
  36. // Get form.
  37. $this->drupalGet('admin/config/media/image-toolkit');
  38. // Test that default toolkit is GD.
  39. $this->assertFieldByName('image_toolkit', 'gd', 'The default image toolkit is GD.');
  40. // Test changing the jpeg image quality.
  41. $edit = ['gd[image_jpeg_quality]' => '70'];
  42. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  43. $this->assertEqual($this->config('system.image.gd')->get('jpeg_quality'), '70');
  44. // Test changing the toolkit.
  45. $edit = ['image_toolkit' => 'test'];
  46. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  47. $this->assertEqual($this->config('system.image')->get('toolkit'), 'test');
  48. $this->assertFieldByName('test[test_parameter]', '10');
  49. // Test changing the test toolkit parameter.
  50. $edit = ['test[test_parameter]' => '0'];
  51. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  52. $this->assertText(t('Test parameter should be different from 0.'), 'Validation error displayed.');
  53. $edit = ['test[test_parameter]' => '20'];
  54. $this->drupalPostForm(NULL, $edit, 'Save configuration');
  55. $this->assertEqual($this->config('system.image.test_toolkit')->get('test_parameter'), '20');
  56. // Test access without the permission 'administer site configuration'.
  57. $this->drupalLogin($this->drupalCreateUser(['access administration pages']));
  58. $this->drupalGet('admin/config/media/image-toolkit');
  59. $this->assertResponse(403);
  60. }
  61. }