color.test 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * Tests for color module.
  5. */
  6. /**
  7. * Tests the Color module functionality.
  8. */
  9. class ColorTestCase extends DrupalWebTestCase {
  10. protected $big_user;
  11. protected $themes;
  12. protected $colorTests;
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Color functionality',
  16. 'description' => 'Modify the Bartik and Garland theme colors and make sure the changes are reflected on the frontend',
  17. 'group' => 'Color',
  18. );
  19. }
  20. function setUp() {
  21. parent::setUp('color');
  22. // Create users.
  23. $this->big_user = $this->drupalCreateUser(array('administer themes'));
  24. // This tests the color module in both Bartik and Garland.
  25. $this->themes = array(
  26. 'bartik' => array(
  27. 'palette_input' => 'palette[bg]',
  28. 'scheme' => 'slate',
  29. 'scheme_color' => '#3b3b3b',
  30. ),
  31. 'garland' => array(
  32. 'palette_input' => 'palette[link]',
  33. 'scheme' => 'greenbeam',
  34. 'scheme_color' => '#0c7a00',
  35. ),
  36. );
  37. theme_enable(array_keys($this->themes));
  38. // Array filled with valid and not valid color values
  39. $this->colorTests = array(
  40. '#000' => TRUE,
  41. '#123456' => TRUE,
  42. '#abcdef' => TRUE,
  43. '#0' => FALSE,
  44. '#00' => FALSE,
  45. '#0000' => FALSE,
  46. '#00000' => FALSE,
  47. '123456' => FALSE,
  48. '#00000g' => FALSE,
  49. );
  50. }
  51. /**
  52. * Tests the Color module functionality.
  53. */
  54. function testColor() {
  55. foreach ($this->themes as $theme => $test_values) {
  56. $this->_testColor($theme, $test_values);
  57. }
  58. }
  59. /**
  60. * Tests the Color module functionality using the given theme.
  61. */
  62. function _testColor($theme, $test_values) {
  63. variable_set('theme_default', $theme);
  64. $settings_path = 'admin/appearance/settings/' . $theme;
  65. $this->drupalLogin($this->big_user);
  66. $this->drupalGet($settings_path);
  67. $this->assertResponse(200);
  68. $edit['scheme'] = '';
  69. $edit[$test_values['palette_input']] = '#123456';
  70. $this->drupalPost($settings_path, $edit, t('Save configuration'));
  71. $this->drupalGet('<front>');
  72. $stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
  73. $this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
  74. $stylesheet_content = join("\n", file($stylesheets[0]));
  75. $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
  76. $this->drupalGet($settings_path);
  77. $this->assertResponse(200);
  78. $edit['scheme'] = $test_values['scheme'];
  79. $this->drupalPost($settings_path, $edit, t('Save configuration'));
  80. $this->drupalGet('<front>');
  81. $stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
  82. $stylesheet_content = join("\n", file($stylesheets[0]));
  83. $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
  84. // Test with aggregated CSS turned on.
  85. variable_set('preprocess_css', 1);
  86. $this->drupalGet('<front>');
  87. $stylesheets = variable_get('drupal_css_cache_files', array());
  88. $stylesheet_content = '';
  89. foreach ($stylesheets as $key => $uri) {
  90. $stylesheet_content .= join("\n", file(drupal_realpath($uri)));
  91. }
  92. $this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
  93. variable_set('preprocess_css', 0);
  94. }
  95. /**
  96. * Tests whether the provided color is valid.
  97. */
  98. function testValidColor() {
  99. variable_set('theme_default', 'bartik');
  100. $settings_path = 'admin/appearance/settings/bartik';
  101. $this->drupalLogin($this->big_user);
  102. $edit['scheme'] = '';
  103. foreach ($this->colorTests as $color => $is_valid) {
  104. $edit['palette[bg]'] = $color;
  105. $this->drupalPost($settings_path, $edit, t('Save configuration'));
  106. if($is_valid) {
  107. $this->assertText('The configuration options have been saved.');
  108. }
  109. else {
  110. $this->assertText('Main background must be a valid hexadecimal CSS color value.');
  111. }
  112. }
  113. }
  114. }