less.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. class LessUnitTest extends DrupalUnitTestCase {
  3. /**
  4. * {@inheritdoc}
  5. */
  6. public static function getInfo() {
  7. return array(
  8. 'name' => 'Less Unit Tests',
  9. 'description' => 'Tests functions that only act on input and do not require a DB.',
  10. 'group' => 'Less',
  11. );
  12. }
  13. public function setUp() {
  14. module_load_include('module', 'less');
  15. module_load_include('inc', 'less', 'includes/less.process');
  16. parent::setUp();
  17. }
  18. /**
  19. * Test the _less_output_path() function.
  20. *
  21. * @see _less_output_path()
  22. */
  23. public function test_less_output_path() {
  24. $less_item = array(
  25. 'less' => array(
  26. 'build_cache_id' => 'Zxz5NVNO0Ad9miD2JeGw1B_3auVKtmJJ7ksCdxaeZ0A',
  27. 'variables' => array(
  28. '@gradient_end' => 'darken(@gradient_start, 10%);',
  29. '@gradient_start' => '#0779bf;',
  30. '@text_glow' => 'blue',
  31. '@test' => 'green',
  32. '@header_from' => 'test',
  33. ),
  34. 'functions' => array(
  35. 'token' => '_less_token_replace',
  36. 'swap' => '_less_demo_reverse',
  37. ),
  38. 'paths' => array(
  39. 0 => 'sites/all/modules/custom/less/less_demo/libs',
  40. ),
  41. 'less_autoprefixer' => TRUE,
  42. 'less_devel' => FALSE,
  43. 'less_source_maps' => FALSE,
  44. 'theme' => 'seven',
  45. 'output_file' => NULL,
  46. 'build_required' => NULL,
  47. 'input_file' => 'sites/all/modules/custom/less/less_demo/styles/less_demo.info.css.less',
  48. ),
  49. );
  50. _less_output_path($less_item, NULL);
  51. $expected_output_file = 'public://less/less_demo.info.aIR_TiwEIzIVLaH9dWKmPfbShza_NoIVp_TPs0tPvaM.css';
  52. $this->assertIdentical($less_item['less']['output_file'], $expected_output_file, 'Output file location processes correctly.');
  53. }
  54. /**
  55. * Test the _less_rewrite_paths() function.
  56. *
  57. * @see _less_rewrite_paths()
  58. */
  59. public function test_less_rewrite_paths() {
  60. $input_file_path = 'sites/all/modules/custom/less/less_demo/styles/less_demo.info.css.less';
  61. $less_compiled_css = <<<'EOD'
  62. #less_demo_gradient .less_demo_logo {
  63. background: transparent url(../images/logo.png) center center no-repeat;
  64. }
  65. EOD;
  66. $expected_rewritten_output_data = <<<EOD
  67. #less_demo_gradient .less_demo_logo {
  68. background: transparent url({$GLOBALS['base_path']}sites/all/modules/custom/less/less_demo/images/logo.png) center center no-repeat;
  69. }
  70. EOD;
  71. $actual_rewritten_output_data = _less_rewrite_paths($input_file_path, $less_compiled_css);
  72. $this->assertIdentical($actual_rewritten_output_data, $expected_rewritten_output_data, 'Rewritten paths are correct.');
  73. }
  74. }