'Follow module', 'description' => 'Test the Follow module', 'group' => 'Follow', ); } /** * Set up the modules and any other */ public function setUp() { // List the modules that should be enabled for this test. parent::setUp('follow_test'); // Create an admin user. $this->adminUser = $this->drupalCreateUser( array('administer blocks') ); } /** * Create one test function here to run all tests from, for speed. */ function testFollow() { $this->_testInstall(); $this->_testIcons(); $this->_testConfigureForm(); $this->_testCssCallback(); } public function _testInstall() { $this->assertTrue(file_exists(_follow_css_get_path()), t('The CSS file was generated on install.')); } public function _testIcons() { $default_style = follow_get_icon_style('small'); // Determine the default icons. $default_icons = $this->_globStyleIconDir($default_style); $styles = follow_icon_styles(); foreach ($styles as $style) { if ($style['name'] == $default_style['name']) { continue; } $icons = $this->_globStyleIconDir($style); $this->verbose(print_r(array_diff($default_icons, $default_icons), 1)); $t_args['@label'] = $style['label']; $this->assertEqual( $default_icons, $icons, t('The @label icon style contains all necessary icons.', $t_args)); } } public function _testConfigureForm() { $url = 'admin/structure/block/manage/follow/site/configure'; $css_path = _follow_css_get_path(); $original_time = filemtime($css_path); $this->drupalLogin($this->adminUser); $this->drupalPost($url, array(), t('Save block')); $new_time = filemtime($css_path); $this->assertNotEqual( $original_time, $new_time, t('The CSS file is regenerated upon saving the block configure form.')); } public function _testCssCallback() { // First, delete the CSS path. file_unmanaged_delete('public://css/follow.css'); // Then do a GET on the path to see if the file is actually a CSS file. $this->drupalGet(_follow_css_get_path()); $this->assertRaw(' * This CSS file is generated by Follow module. DO NOT edit it directly.', t('The Follow CSS menu callback displays the generated CSS.')); } protected function _globStyleIconDir(array $style) { $path = trim(_follow_style_icon_path($style), '/'); $directory = DRUPAL_ROOT . "/{$path}"; $pattern = "{$directory}/*.png"; foreach (glob($pattern) as $filename) { $files[] = str_replace($directory, '', $filename); } sort($files); return $files; } }