og_sm-8.x-1.0/og_sm_taxonomy/tests/OgSmTaxonomyContextTestCase.test

og_sm_taxonomy/tests/OgSmTaxonomyContextTestCase.test
<?php
/**
 * @file
 * Tests about the Site Taxonomies.
 */

/**
 * Tests about the Site Taxonomy Context handler.
 */
class OgSmTaxonomyContextTestCase extends OgSmWebTestCase {
  /**
   * Site Nodes to run the tests with.
   *
   * @var object
   */
  private $siteNode1;
  private $siteNode2;

  /**
   * Vocabulary "categories" to run tests with.
   *
   * @var object
   */
  private $vocabCategories;

  /**
   * Vocabulary "tags" to run tests with.
   *
   * @var object
   */
  private $vocabTags;

  /**
   * Category term without Sites to test with.
   *
   * @var object
   */
  private $termCategoryWithoutSite;

  /**
   * Category term with one Site to test with.
   *
   * @var object
   */
  private $termCategoryWithSite;

  /**
   * Category term with multiple Sites to test with.
   *
   * @var object
   */
  private $termCategoryWithSites;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => t('Site Taxonomy : Context'),
      'description' => t('Tests Site Taxonomy Context functionality.'),
      'group' => t('Organic Groups Site Manager'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    // Enable required modules.
    $modules = array('og_sm_taxonomy');
    parent::setUp($modules);

    // Create the Site type.
    $type = $this->ogSmCreateGroupNodeType();
    og_sm_site_type_add($type);
    $this->siteNode1 = $this->ogSmCreateGroup($type);
    $this->siteNode2 = $this->ogSmCreateGroup($type);

    // Create vocabularies.
    $this->vocabCategories = $this->ogSmCreateGroupVocabulary('test_categories');
    $this->vocabTags = $this->ogSmCreateGroupVocabulary('test_tags');

    // Create terms.
    $this->termCategoryWithoutSite = $this->ogSmCreateTerm(
      $this->vocabCategories,
      'category-without-sites'
    );
    $this->termCategoryWithSite = $this->ogSmCreateTerm(
      $this->vocabCategories,
      'category-with-site',
      array($this->siteNode1)
    );
    $this->termCategoryWithSites = $this->ogSmCreateTerm(
      $this->vocabCategories,
      'category-with-sites',
      array($this->siteNode1, $this->siteNode2)
    );
  }

  /**
   * Test the context handler.
   */
  public function testContextHandlerTerm() {
    // Outside a Site.
    $_GET['q'] = 'taxonomy/term/' . $this->termCategoryWithoutSite->tid;
    $this->assertNull(
      og_sm_taxonomy_og_context_handler_term(),
      'No context for terms outside Site(s).'
    );

    // Inside a Site.
    $_GET['q'] = 'taxonomy/term/' . $this->termCategoryWithSite->tid;
    $expected = array(
      'node' => array((int) $this->siteNode1->nid),
    );
    $this->assertEqual(
      $expected,
      og_sm_taxonomy_og_context_handler_term(),
      'Term with single Site membership has context.'
    );

    // Inside multiple Sites.
    $_GET['q'] = 'taxonomy/term/' . $this->termCategoryWithSites->tid . '/edit';
    $expected = array(
      'node' => array(
        (int) $this->siteNode1->nid,
        (int) $this->siteNode2->nid,
      ),
    );
    $this->assertEqual(
      $expected,
      og_sm_taxonomy_og_context_handler_term(),
      'Term with multiple Site membership has multiple contexts.'
    );
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc