/** * Check that functions creating directories in drupal files work as expected. * * If this test fails, double check recursively that permission are correctly set * for files directory. Group should at least be _www so that phpunit is able to create * directories. * * This is an example of expected directory structure : * * files * okcdesign * mytheme * theme_custom_settings.scss * app.css * @depends test_foundation_ui_get_okcdesign_custom_directory_path */ function test_foundation_ui_create_files_directories() { $theme_test_directory = 'phpunit_test_' . rand(); $expected_path = foundation_ui_get_okcdesign_custom_directory_path() . '/' . $theme_test_directory; $result = foundation_ui_create_files_directories($theme_test_directory); $this->assertTrue($result); $this->assertFileExists($expected_path); rmdir($expected_path); }
/** * Recompile all theme scss on plugin form submission. * @param $form * @param $form_state */ function foundation_ui_settings_form_submit($form, $form_state) { // no values submitted for custom scss settings, abort. if (empty($form_state['values']['theme_plugin_settings_foundation_ui'])) { return; } $theme = arg(3); $themepath = drupal_get_path('theme', $theme); // create directories, if they do not exist, to store submitted scss. $result = foundation_ui_create_files_directories($theme); if (!$result) { drupal_set_message('error', 'Directories creation failed. Please check your files directory permissions and retry'); } // Create a valid scss string from submitted values. $values = foundation_ui_prepare_values($form_state['values']['theme_plugin_settings_foundation_ui']); $new_scss = foundation_ui_create_scss_string_from_array($values); // if submitted scss settings are the same than scss settings already stored in file, do nothing more. $old_scss = foundation_ui_get_theme_custom_scss($theme); if ($new_scss == $old_scss) { return; } // store scss in a file. $result = file_put_contents(foundation_ui_get_theme_scss_file_path($theme), $new_scss); if (!$result) { drupal_set_message('error', 'Fail to write custom scss in a file, please check your files directory permissions and retry.'); } // get app.scss from this theme. $app_scss_content = file($themepath . '/scss/app.scss'); // add @import "user_settings" to app.scss content, just after @import "settings" line. $scss_string = foundation_ui_rebuild_scss_import_file($app_scss_content); // let phpscss compile this file content to css $css = foundation_ui_compile_theme_scss($theme, $scss_string); // store compiled css into a files/okcdesign/{theme_name}/app.css file. // save compiled css to a file, that will be served by foundation plugin if it can load it. $result = file_put_contents(foundation_ui_get_theme_css_file_path($theme), $css); if (!$result) { drupal_set_message('error', 'Fail to write custom scss in a file, please check your files directory permissions and retry.'); } drupal_set_message("All scss files have been recompiled to css files with new settings."); }