You are here

private function TagadelicTaxonomyTestCase::createNodesWithTags in Tagadelic 7.2

Creates $amount nodes with terms attached.

Fuck it, I am poking around in the database directly instead of testing and preparing all this field, entity, admin-user and whatnot. I am not interested in whether or not we can store nodes with tags, only that they are there. By adding them to the database, we achieve that.

5 calls to TagadelicTaxonomyTestCase::createNodesWithTags()
TagadelicTaxonomyTestCase::createVocAndTags in tests/tagadelic_taxonomy.test
TagadelicTaxonomyTestCase::testBlockRendering in tests/tagadelic_taxonomy.test
TagadelicTaxonomyTestCase::testHasWeightedTags in tests/tagadelic_taxonomy.test
TagadelicTaxonomyTestCase::testOnlyHasTagsFromSelectedVocabularies in tests/tagadelic_taxonomy.test
TagadelicTaxonomyTestCase::testOrdersTagsByUsage in tests/tagadelic_taxonomy.test

File

tests/tagadelic_taxonomy.test, line 225

Class

TagadelicTaxonomyTestCase

Code

private function createNodesWithTags($amount) {
  $this->nodes = array();
  $attachable = $this->tags;
  for ($i = 0; $i < $amount; $i++) {

    // Post an article.
    $node = new StdClass();
    $node->title = $this
      ->randomName();
    $node->type = "story";
    node_save($node);
    $this->nodes[] = $node;

    // Attach the terms
    $query = db_insert('taxonomy_index')
      ->fields(array(
      'nid',
      'tid',
      'sticky',
      'created',
    ));
    foreach ($attachable as $tag) {
      $query
        ->values(array(
        'nid' => $node->nid,
        'tid' => $tag->tid,
        'sticky' => TRUE,
        'created' => $node->created,
      ));
    }
    $query
      ->execute();

    //remove one tag, so the next node gets one less tag attached.
    array_shift($attachable);
  }
  return $this;
}