View source
<?php
namespace Drupal\taxonomy_menu\Tests;
class TaxonomyMenuFunctionalTest extends TaxonomyMenuWebTestCase {
public static function getInfo() {
return array(
'name' => 'Vocabulary interface',
'description' => 'Test the taxonomy menu vocabulary interface.',
'group' => 'Taxonomy menu',
);
}
function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser(array(
'administer taxonomy',
'administer menu',
'bypass node access',
));
$this
->drupalLogin($admin_user);
$this->vocabulary = $this
->createVocabulary();
$this->terms_hierarchy = $this
->createTermsHierarchy();
}
public function testTaxonomyMenuVocabularyInterface() {
$menu_name = 'account';
$vid = $this->vocabulary
->id();
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$edit = array();
$edit['taxonomy_menu[vocab_parent]'] = $menu_name . ':0';
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('The Taxonomy menu has been created.'));
$edit['taxonomy_menu[options_structure][hide_empty_terms]'] = TRUE;
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$this
->assertRaw(t('The Taxonomy menu has been updated.'));
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$this
->assertRaw(t('The Taxonomy menu was not updated. Nothing to update.'));
$edit['taxonomy_menu[vocab_parent]'] = '0';
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$this
->assertRaw(t('The Taxonomy menu has been removed.'));
}
public function testTaxonomyMenuTermsOverviewInterface() {
$this->terms_hierarchy = $this
->createTermsHierarchy($this->vocabulary
->id());
$term7 = $this->terms_hierarchy[7];
$edit = array(
'taxonomy_menu[vocab_parent]' => 'main:0',
'taxonomy_menu[sync]' => TRUE,
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->id(), $edit, t('Save'));
$this
->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/overview');
$edit = array(
'terms[tid:' . $term7
->id() . ':0][term][tid]' => $term7
->id(),
'terms[tid:' . $term7
->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term7
->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term7
->id() . ':0][weight]' => -5,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('The Taxonomy menu has been updated.'));
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/overview', array(), t('Reset to alphabetical'));
$this
->drupalPostForm(NULL, array(), t('Reset to alphabetical'));
$this
->assertRaw(t('The Taxonomy menu has been updated.'));
}
public function testTaxonomyMenuTermInterface() {
$menu_name = 'main';
$vocab_settings['taxonomy_menu[vocab_parent]'] = $menu_name . ':0';
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->id(), $vocab_settings, t('Save'));
$term_settings = array(
'name[0][value]' => $this
->randomName(12),
'description[0][value]' => $this
->randomName(100),
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/add', $term_settings, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($term_settings['name[0][value]']);
$term = reset($terms);
$this
->assertRaw(t('Added term %term to taxonomy menu %menu_name.', array(
'%term' => $term_settings['name[0][value]'],
'%menu_name' => $menu_name,
)));
$new_term_settings = array(
'name[0][value]' => $this
->randomName(12),
'description[0][value]' => $this
->randomName(100),
);
$this
->drupalPostForm('taxonomy/term/' . $term
->id() . '/edit', $new_term_settings, t('Save'));
$this
->assertRaw(t('Updated term %term in taxonomy menu %menu_name.', array(
'%term' => $new_term_settings['name[0][value]'],
'%menu_name' => $menu_name,
)));
$this
->clickLink(t('Delete'));
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('Deleted term %term from taxonomy menu %menu_name.', array(
'%term' => $new_term_settings['name[0][value]'],
'%menu_name' => $menu_name,
)));
}
}