fivestar.base.test
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @file
* Based test file for the Fivestar module.
*/
class FivestarBaseTestCase extends AJAXTestCase {
// Using testing profile.
// @see http://groups.drupal.org/node/217189
protected $profile = 'testing';
// Set up our basic users.
protected $admin_user;
protected $voter;
public function setUp() {
parent::setUp(array('fivestar', 'dblog'));
$type = $this->drupalCreateContentType(array('type' => 'test_node_type', 'name' => 'test_node_type'));
$this->admin_user = $this->drupalCreateUser(array('create test_node_type content', 'rate content'));
$this->voter_user = $this->drupalCreateUser(array('rate content'));
}
/**
* Add a fivestar field to a content type.
*
* @param $options
* An associative array of options for the field and instance.
*/
public function createFivestarField($options = array()) {
$options = $options + array(
'content_type' => 'test_node_type',
'widget_type' => 'stars',
'display' => array(),
);
$field = array(
'field_name' => 'fivestar_test',
'type' => 'fivestar',
'cardinality' => 1,
'settings' => array(
'axis' => 'vote',
),
);
$instance = array(
'entity_type' => 'node',
'field_name' => 'fivestar_test',
'label' => 'Fivestar test field',
'bundle' => $options['content_type'],
'widget' => array(
'type' => $options['widget_type'],
'settings' => array(
'widget' => array(
'fivestar_widget' => 'default',
),
),
),
'settings' => array(
'axis' => 'vote',
'stars' => '5',
),
'display' => $options['display'],
);
field_create_field($field);
field_create_instance($instance);
}
}