You are here

function TagadelicServiceTest::testTagadelicService in Tagadelic 8.3

Test block placement.

File

src/Tests/TagadelicServiceTest.php, line 117

Class

TagadelicServiceTest
Tests for tagadelic service.

Namespace

Drupal\tagadelic\Tests

Code

function testTagadelicService() {
  $user = $this
    ->drupalCreateUser([
    'administer taxonomy',
    'bypass node access',
  ]);
  $this
    ->drupalLogin($user);

  // Create 4 taxonomy terms and and 4 nodes
  // Add various combinations of ther terms' ids to the
  // entity reference field on the nodes
  $term1 = $this
    ->createTerm($this->vocabulary);
  $term2 = $this
    ->createTerm($this->vocabulary);
  $term3 = $this
    ->createTerm($this->vocabulary);
  $term4 = $this
    ->createTerm($this->vocabulary);
  $node = array();
  $node['type'] = 'article';
  $node['field_views_testing_tags'][]['target_id'] = $term1
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term2
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term3
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term4
    ->id();
  $node1 = $this
    ->drupalCreateNode($node);
  $node['field_views_testing_tags'][] = array();
  $node['field_views_testing_tags'][]['target_id'] = $term1
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term2
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term3
    ->id();
  $node2 = $this
    ->drupalCreateNode($node);
  $node['field_views_testing_tags'][] = array();
  $node['field_views_testing_tags'][]['target_id'] = $term1
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term2
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term3
    ->id();
  $node3 = $this
    ->drupalCreateNode($node);
  $node['field_views_testing_tags'][] = array();
  $node['field_views_testing_tags'][]['target_id'] = $term1
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term2
    ->id();
  $node['field_views_testing_tags'][]['target_id'] = $term3
    ->id();
  $node4 = $this
    ->drupalCreateNode($node);

  // Create the tervice and check that it is returning tags
  $service = \Drupal::service('tagadelic.tagadelic_taxonomy');
  $tags = $service
    ->getTags();
  $this
    ->assertTrue(count($tags) > 0);
  $this
    ->assertEqual(4, count($tags));
  $tag = array_pop($tags);
  $this
    ->assertEqual('Drupal\\tagadelic\\TagadelicTag', get_class($tag));
}