Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 31, 2012
Bèr Kessels Rewrite SQL using entity. 378fbc0
Bèr Kessels Test expected weights. a35e5ec
Bèr Kessels Map with counts and expected weights. 92fc89d
Showing with 43 additions and 20 deletions.
  1. +10 −20 tagadelic_taxonomy.module
  2. +33 −0 tests/TagadelicCloudTest.php
View
30 tagadelic_taxonomy.module
@@ -46,31 +46,21 @@ function tagadelic_taxonomy_theme($existing, $type, $theme, $path) {
function tagadelic_taxonomy_get_tags() {
$tags = array();
- /**
- see http://drupal.stackexchange.com/q/54483/787
- $query = db_select('taxonomy_term_data', 't');
+ $query = db_select('taxonomy_index', 'i');
- $query->addField('t', 'tid');
- $query->addField('t', 'name');
- $query->addField('t', 'description');
- $query->addField('COUNT(i.nid)', 'count');
+ $alias = $query->leftjoin('taxonomy_term_data', 't', '%alias.tid = i.tid');
- $query->leftjoin('taxonomy_index', 'i', 'i.nid = t.nid');
- $query->range(0, 60)
- ->groupBy('i.nid');
-
- print($query);
+ $query->addExpression('COUNT(i.nid)', 'count');
+ $query->addField($alias, 'tid');
+ $query->addField($alias, 'name');
+ $query->addField($alias, 'description');
- result = $query->execute();*/
+ $query->range(0, 60)
+ ->groupBy("i.tid");
- $result = db_query("SELECT t.tid, t.name, t.description, COUNT(i.nid) AS count
- FROM taxonomy_index AS i
- LEFT JOIN taxonomy_term_data AS t ON i.tid = t.tid
- GROUP BY i.tid
- LIMIT 60");
+ $result = $query->execute();
- /*foreach ($result as $term) {*/
- while($term = $result->fetchObject()) {
+ foreach ($result as $term) {
$tag = new TagadelicTag($term->tid, $term->name, $term->count);
$tag->set_link("taxonomy/term/{$term->tid}");
$tag->set_weight(1);
View
33 tests/TagadelicCloudTest.php
@@ -110,10 +110,43 @@ public function testGetCalculatedTags() {
foreach ($this->mock_tags as $mock_tag) {
$mock_tag->expects($this->once())
->method('set_weight')
+ ->with($this->greaterThan(0))
->will($this->returnSelf());
$mocks[] = $mock_tag;
}
$this->object = new TagadelicCloud(1337, $mocks);
$this->object->get_tags();
}
+
+ /**
+ * Get Tags should calculate the weights
+ */
+ public function testGetCalculatedWeights() {
+ $mocks = array();
+ $assert_table = array(
+ // name , count , weight
+ array("Mary Read" , 1 , 1),
+ array("Jean Fleury" , 1 , 1),
+ array("François Le Clerc" , 1 , 1),
+ array("Blackbeard" , 2 , 1),
+ array("Henry Morgan" , 3 , 2),
+ array("Bartolomew Roberts" , 10 , 3),
+ array("Stede Bonnet" , 20 , 4),
+ array("Edward Low" , 40 , 5),
+ array("Anne Bonny" , 100 , 6),
+ );
+ $i = 1;
+
+ foreach($assert_table as $assertion) {
+ $mock = $this->getMock("TagadelicTag", array("name", "count", "set_weight"), array($i++, $assertion[0], $assertion[1]));
+ $mock->expects($this->once())
+ ->method("set_weight")
+ ->with($assertion[2])
+ ->will($this->returnSelf());
+
+ $mocks[] = $mock;
+ }
+ $this->object = new TagadelicCloud(1337, $mocks);
+ $this->object->get_tags();
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.