Projet

Général

Profil

Paste
Télécharger (5,28 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / sweaver / tests / sweaver.admin.test @ 384fc62a

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for sweaver backend
6
 */
7

    
8
class sweaverAdministration extends DrupalWebTestCase {
9
  /**
10
   * Implementation of getInfo().
11
   */
12
  public static function getInfo() {
13
    return array(
14
      'name' => t('Sweaver administration'),
15
      'description' => t('Tests for the administration of sweaver, except for plugins and styles.'),
16
      'group' => t('Sweaver'),
17
    );
18
  }
19

    
20
  /**
21
   * Implementation of setUp().
22
   */
23
  function setUp() {
24
    parent::setUp('sweaver', 'ctools');
25

    
26
    $this->perms = '';
27
    $this->image_path = 'misc/druplicon.png';
28
    $modules = array('sweaver', 'ctools');
29

    
30
    $this->admin_user = $this->drupalCreateUser(array('use editor', 'configure sweaver', 'bypass node access', 'administer nodes', 'access administration pages'));
31
    $this->drupalLogin($this->admin_user);
32
  }
33

    
34
  /**
35
   * Debug helper function. Writes values away to a text file in the files directory.
36
   */
37
  function _debugHelper($value, $writetype = 'a+') {
38
    $debug = fopen($this->originalFileDirectory .'/simpletestdebug.txt', 'a+');
39
    fwrite($debug, print_r($value, TRUE) ."\n");
40
    fclose($debug);
41
  }
42

    
43
  /**
44
   * Core administration tests for Sweaver.
45
   */
46
  function testCoreAdminSweaver() {
47
    $editor_tests = t('Basic admin testing');
48

    
49
    // Setting screen: test that editor is enabled or disabled with checkbox and path settings.
50
    $edit['sweaver_enabled'] = FALSE;
51
    $this->drupalPost('admin/config/user-interface/sweaver', $edit, t('Save configuration'));
52
    $this->drupalGet('user');
53
    $this->assertNoRaw('sweaver-frontend', t('Editor disabled'), $editor_tests);
54

    
55
    $edit['sweaver_enabled'] = TRUE;
56
    $this->drupalPost('admin/config/user-interface/sweaver', $edit, t('Save configuration'));
57
    $this->drupalGet('user');
58
    $this->assertRaw('sweaver-frontend', t('Editor enabled'), $editor_tests);
59
    $this->drupalGet('node/add');
60
    $this->assertNoRaw('sweaver-frontend', t('Editor not set'), $editor_tests);
61

    
62
    // Selectors enabled/disabled.
63
    $this->drupalGet('admin/config/user-interface/sweaver/editor/disable/selector/body');
64
    $this->drupalGet('user');
65
    $status = (strpos($this->content, '"description": "Body"') && strpos($this->content, '"description":"Body"'));
66
    $this->assertFalse($status, t('Body selector disabled'), $editor_tests);
67

    
68
    $this->drupalGet('admin/config/user-interface/sweaver/editor/enable/selector/body');
69
    $this->drupalGet('user');
70
    $status = (strpos($this->content, '"description": "Body"') || strpos($this->content, '"description":"Body"'));
71
    $this->assertTrue($status, t('Body selector enabled'), $editor_tests);
72

    
73
    // Properties enabled/disabled.
74
    $this->drupalGet('admin/config/user-interface/sweaver/editor/disable/property/background-color');
75
    $this->drupalGet('user');
76
    $this->assertNoRaw('id="background-color"', t('Background color disabled'), $editor_tests);
77
    $this->drupalGet('admin/config/user-interface/sweaver/editor/enable/property/background-color');
78
    $this->drupalGet('user');
79
    $this->assertRaw('id="background-color"', t('Background color enabled'), $editor_tests);
80

    
81
    // Types enabled/disabled.
82
    $this->drupalGet('admin/config/user-interface/sweaver/editor/disable/type/block');
83
    $this->drupalGet('user');
84
    $status = (strpos($this->content, '"types":{"block":') && strpos($this->content, '"types": { "block":'));
85
    $this->assertFalse($status, t('Type block disabled'), $editor_tests);
86
    $this->drupalGet('admin/config/user-interface/sweaver/editor/enable/type/block');
87
    $this->drupalGet('user');
88
    $status = (strpos($this->content, '"types":{"block":') || strpos($this->content, '"types": { "block":'));
89
    $this->assertTrue($status, t('Type block enabled'), $editor_tests);
90
  }
91

    
92
  /**
93
   * Advanced administration tests for Sweaver.
94
   */
95
  function testAdvancedAdminSweaver() {
96
    $editor_tests = t('Special admin testing');
97

    
98
    // Public path.
99
    $public_path = variable_get('file_public_path', conf_path() . '/files');
100

    
101
    // Upload image.
102
    $edit = array(
103
      'description' => 'Image test',
104
      'files[image]' => realpath($this->image_path),
105
    );
106
    $this->drupalPost('admin/config/user-interface/sweaver/images/add', $edit, t('Save image'));
107
    $this->assertText(t('Image Image test has been saved.'), t('Image uploaded'), $editor_tests);
108
    $this->assertTrue(file_exists($public_path . '/sweaver/sweaver_image_1.png'), t('Image uploaded'), $editor_tests);
109
    $this->drupalGet('user');
110
    $this->assertRaw('value="'. $GLOBALS['base_url'] . '/' . $public_path.'/sweaver/sweaver_image_1.png"', t('Image found in editor'), $editor_tests);
111

    
112
    $this->drupalGet('user');
113

    
114
    $style_url = image_style_url('medium', 'public://sweaver/sweaver_image_1.png');
115
    $raw_style = '<option value="'. $style_url .'">Image test (sweavertest)</option>';
116
    $this->assertNoRaw($raw_style, t('Styled version of image not found'), $editor_tests);
117

    
118
    // Enable styles.
119
    $edit = array(
120
      'sweaver_plugin_images_styles' => 1,
121
    );
122
    $this->drupalPost('admin/config/user-interface/sweaver/images', $edit, t('Save configuration'));
123
    $this->drupalGet('user');
124
    $this->assertRaw('styles/medium/public/sweaver/sweaver_image_1.png', t('Styled version of image found'), $editor_tests);
125
  }
126
}
127