Projet

Général

Profil

Paste
Télécharger (1,93 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / fivestar / test / fivestar.base.test @ d50a36e0

1
<?php
2

    
3
/**
4
 * @file
5
 * Test base for the Fivestar module.
6
 */
7

    
8
/**
9
 * Base class for Fivestar Ajax tests.
10
 */
11
class FivestarBaseTestCase extends AJAXTestCase {
12

    
13
  /**
14
   * Use testing profile.
15
   *
16
   * @see http://groups.drupal.org/node/217189
17
   */
18
  protected $profile = 'testing';
19

    
20
  /**
21
   * A user with permission to administer Fivestar.
22
   */
23
  protected $adminUser;
24

    
25
  /**
26
   * A user with permission to vote.
27
   */
28
  protected $voterUser;
29

    
30
  /**
31
   * {@inheritdoc}
32
   */
33
  public function setUp() {
34
    parent::setUp(array('fivestar', 'dblog'));
35

    
36
    $type = $this->drupalCreateContentType(array('type' => 'test_node_type', 'name' => 'test_node_type'));
37
    $this->adminUser = $this->drupalCreateUser(array('create test_node_type content', 'rate content'));
38
    $this->voterUser = $this->drupalCreateUser(array('rate content'));
39
  }
40

    
41
  /**
42
   * Add a fivestar field to a content type.
43
   *
44
   * @param array $options
45
   *   An associative array of options for the field and instance.
46
   */
47
  public function createFivestarField(array $options = array()) {
48
    $options = $options + array(
49
      'content_type' => 'test_node_type',
50
      'widget_type' => 'stars',
51
      'display' => array(),
52
    );
53
    $field = array(
54
      'field_name' => 'fivestar_test',
55
      'type' => 'fivestar',
56
      'cardinality' => 1,
57
      'settings' => array(
58
        'axis' => 'vote',
59
      ),
60
    );
61
    $instance = array(
62
      'entity_type' => 'node',
63
      'field_name' => 'fivestar_test',
64
      'label' => 'Fivestar test field',
65
      'bundle' => $options['content_type'],
66
      'widget' => array(
67
        'type' => $options['widget_type'],
68
        'settings' => array(
69
          'widget' => array(
70
            'fivestar_widget' => 'default',
71
          ),
72
        ),
73
      ),
74
      'settings' => array(
75
        'axis' => 'vote',
76
        'stars' => '5',
77
      ),
78
      'display' => $options['display'],
79
    );
80

    
81
    field_create_field($field);
82
    field_create_instance($instance);
83
  }
84

    
85
}