| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* @file topichubs.test
|
| 4 |
*/
|
| 5 |
|
| 6 |
class TopicHubsTestCase extends DrupalWebTestCase {
|
| 7 |
|
| 8 |
function setUp() {
|
| 9 |
parent::setUp('views', 'content', 'topichubs', 'topichubs_most_recent');
|
| 10 |
}
|
| 11 |
|
| 12 |
function tearDown() {
|
| 13 |
parent::tearDown();
|
| 14 |
}
|
| 15 |
|
| 16 |
function createVocabulary() {
|
| 17 |
$vocab = array();
|
| 18 |
$vocab['name'] = $this->randomName(20);
|
| 19 |
taxonomy_save_vocabulary($vocab);
|
| 20 |
return $vocab;
|
| 21 |
}
|
| 22 |
|
| 23 |
function createTerm($vid, $overrides = array()) {
|
| 24 |
$term = array(
|
| 25 |
'vid' => $vid,
|
| 26 |
'name' => $this->randomName(30),
|
| 27 |
'description' => $this->randomName(200),
|
| 28 |
);
|
| 29 |
$term += $overrides;
|
| 30 |
taxonomy_save_term($term);
|
| 31 |
return (object)$term;
|
| 32 |
}
|
| 33 |
|
| 34 |
static function stubHubNode($nid = NULL) {
|
| 35 |
$node = new stdClass;
|
| 36 |
$node->nid = $nid;
|
| 37 |
$node->topichub = new stdClass;
|
| 38 |
$node->topichub->config = array();
|
| 39 |
return $node;
|
| 40 |
}
|
| 41 |
|
| 42 |
function createHubNode($conditions = array()) {
|
| 43 |
$node = $this->drupalCreateNode(array('type' => 'topichub'));
|
| 44 |
$node->topichub = new stdClass;
|
| 45 |
$node->topichub->config = array();
|
| 46 |
$node->topichub->conditions = $conditions;
|
| 47 |
topichub_insert($node);
|
| 48 |
return $node;
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
|
| 53 |
class TopicHubViewsFilter extends TopicHubsTestCase {
|
| 54 |
function getInfo() {
|
| 55 |
return array(
|
| 56 |
'name' => t('Topic Hubs Views Filter'),
|
| 57 |
'description' => t('Test the taxonomy expression views filter'),
|
| 58 |
'group' => t('Topic Hubs')
|
| 59 |
);
|
| 60 |
}
|
| 61 |
|
| 62 |
// Test the views filter
|
| 63 |
function testTopicHubViewsFilter() {
|
| 64 |
$vocab1 = $this->createVocabulary();
|
| 65 |
$vocab2 = $this->createVocabulary();
|
| 66 |
$term1 = $this->createTerm($vocab1['vid']);
|
| 67 |
$term2 = $this->createTerm($vocab2['vid']);
|
| 68 |
$th = $this->createHubNode(array(array($term1->tid), array($term2->tid)));
|
| 69 |
|
| 70 |
$node1 = $this->drupalCreateNode();
|
| 71 |
$taxonomy1 = array($term1->tid => $term1);
|
| 72 |
taxonomy_node_save($node1, $taxonomy1);
|
| 73 |
|
| 74 |
$node2 = $this->drupalCreateNode();
|
| 75 |
$taxonomy2 = array($term2->tid => $term2);
|
| 76 |
taxonomy_node_save($node2, $taxonomy2);
|
| 77 |
|
| 78 |
$node3 = $this->drupalCreateNode();
|
| 79 |
$taxonomy3 = array($term1->tid => $term1, $term2->tid => $term2);
|
| 80 |
taxonomy_node_save($node3, $taxonomy3);
|
| 81 |
|
| 82 |
$view = views_get_view('topichub_most_recent');
|
| 83 |
$view->add_item('default', 'filter', 'topichub', 'nid', array('value' => $th->nid));
|
| 84 |
$view->execute('default');
|
| 85 |
$results = $view->result;
|
| 86 |
|
| 87 |
$this->assertEqual(3, count($results), '3 results should be returned but ' . count($results) . ' were');
|
| 88 |
$this->assertEqual($node1->nid, $results[0]->nid, 'Wrong first result');
|
| 89 |
$this->assertEqual($node2->nid, $results[1]->nid, 'Wrong second result');
|
| 90 |
$this->assertEqual($node3->nid, $results[2]->nid, 'Wrong third result');
|
| 91 |
}
|
| 92 |
|
| 93 |
}
|
| 94 |
|
| 95 |
class TopicHubViewsArgument extends TopicHubsTestCase {
|
| 96 |
function getInfo() {
|
| 97 |
return array(
|
| 98 |
'name' => t('Topic Hubs Views Argument'),
|
| 99 |
'description' => t('Test the taxonomy expression views argument'),
|
| 100 |
'group' => t('Topic Hubs')
|
| 101 |
);
|
| 102 |
}
|
| 103 |
|
| 104 |
// Test the views filter
|
| 105 |
function testTopicHubViewsArgument() {
|
| 106 |
$vocab1 = $this->createVocabulary();
|
| 107 |
$vocab2 = $this->createVocabulary();
|
| 108 |
$term1 = $this->createTerm($vocab1['vid']);
|
| 109 |
$term2 = $this->createTerm($vocab2['vid']);
|
| 110 |
$th = $this->createHubNode(array(array($term1->tid), array($term2->tid)));
|
| 111 |
|
| 112 |
$node1 = $this->drupalCreateNode();
|
| 113 |
$taxonomy1 = array($term1->tid => $term1);
|
| 114 |
taxonomy_node_save($node1, $taxonomy1);
|
| 115 |
|
| 116 |
$node2 = $this->drupalCreateNode();
|
| 117 |
$taxonomy2 = array($term2->tid => $term2);
|
| 118 |
taxonomy_node_save($node2, $taxonomy2);
|
| 119 |
|
| 120 |
$node3 = $this->drupalCreateNode();
|
| 121 |
$taxonomy3 = array($term1->tid => $term1, $term2->tid => $term2);
|
| 122 |
taxonomy_node_save($node3, $taxonomy3);
|
| 123 |
|
| 124 |
$view = views_get_view('topichub_most_recent');
|
| 125 |
$view->set_arguments(array($th->nid));
|
| 126 |
$view->execute('default');
|
| 127 |
$results = $view->result;
|
| 128 |
|
| 129 |
$this->assertEqual(3, count($results), '3 results should be returned but ' . count($results) . ' were');
|
| 130 |
$this->assertEqual($node1->nid, $results[0]->nid, 'Wrong first result');
|
| 131 |
$this->assertEqual($node2->nid, $results[1]->nid, 'Wrong second result');
|
| 132 |
$this->assertEqual($node3->nid, $results[2]->nid, 'Wrong third result');
|
| 133 |
}
|
| 134 |
|
| 135 |
}
|
| 136 |
|
| 137 |
class TopicHubExpression extends TopicHubsTestCase {
|
| 138 |
function getInfo() {
|
| 139 |
return array(
|
| 140 |
'name' => t('Topic Hubs Expression'),
|
| 141 |
'description' => t('Test things that deal with the expression'),
|
| 142 |
'group' => t('Topic Hubs')
|
| 143 |
);
|
| 144 |
}
|
| 145 |
|
| 146 |
// Test that a term delete removes it from the expressions
|
| 147 |
function testTermDelete() {
|
| 148 |
$vocab1 = $this->createVocabulary();
|
| 149 |
$vocab2 = $this->createVocabulary();
|
| 150 |
$term1 = $this->createTerm($vocab1['vid']);
|
| 151 |
$term2 = $this->createTerm($vocab2['vid']);
|
| 152 |
$node = parent::stubHubNode(time());
|
| 153 |
|
| 154 |
$node->topichub->conditions = array(array($term1->tid), array($term2->tid));
|
| 155 |
topichub_insert($node);
|
| 156 |
|
| 157 |
taxonomy_del_term($term1->tid);
|
| 158 |
|
| 159 |
$testnode = parent::stubHubNode();
|
| 160 |
$testnode->nid = $node->nid;
|
| 161 |
topichub_load($testnode);
|
| 162 |
|
| 163 |
$this->assertEqual(1, count($testnode->topichub->conditions), 'Only one term should exist');
|
| 164 |
$this->assertEqual($term2->tid, $testnode->topichub->conditions[0][0], 'Wrong term id remains');
|
| 165 |
}
|
| 166 |
|
| 167 |
}
|