danielebarchiesi@2: admin_user = $this->drupalCreateUser(array( danielebarchiesi@2: 'access administration pages', danielebarchiesi@2: 'administer content types', danielebarchiesi@2: 'administer menu', danielebarchiesi@2: 'create page content', danielebarchiesi@2: 'edit any page content', danielebarchiesi@2: 'delete any page content', danielebarchiesi@2: )); danielebarchiesi@2: danielebarchiesi@2: $this->menu_attributes_new = array( danielebarchiesi@2: 'title' => $this->randomName(10), danielebarchiesi@2: 'id' => $this->randomName(10), danielebarchiesi@2: 'name' => $this->randomName(10), danielebarchiesi@2: 'rel' => $this->randomName(10), danielebarchiesi@2: 'class' => $this->randomName(10), danielebarchiesi@2: 'style' => $this->randomName(10), danielebarchiesi@2: 'target' => '_top', danielebarchiesi@2: 'accesskey' => $this->randomName(1), danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: $this->menu_attributes_edit = array( danielebarchiesi@2: 'title' => $this->randomName(10), danielebarchiesi@2: 'id' => $this->randomName(10), danielebarchiesi@2: 'name' => $this->randomName(10), danielebarchiesi@2: 'rel' => $this->randomName(10), danielebarchiesi@2: 'class' => $this->randomName(10), danielebarchiesi@2: 'style' => $this->randomName(10), danielebarchiesi@2: 'target' => '_self', danielebarchiesi@2: 'accesskey' => $this->randomName(1), danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Add or edit a menu link using the menu module UI. danielebarchiesi@2: * danielebarchiesi@2: * @param integer $plid Parent menu link id. danielebarchiesi@2: * @param string $link Link path. danielebarchiesi@2: * @param string $menu_name Menu name. danielebarchiesi@2: * danielebarchiesi@2: * @return array Menu link created. danielebarchiesi@2: */ danielebarchiesi@2: function crudMenuLink($mlid = 0, $plid = 0, $link = '', $menu_name = 'navigation') { danielebarchiesi@2: // View add/edit menu link page. danielebarchiesi@2: if (empty($mlid)) { danielebarchiesi@2: $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); danielebarchiesi@2: $menu_attributes = $this->menu_attributes_new; danielebarchiesi@2: } danielebarchiesi@2: else { danielebarchiesi@2: $this->drupalGet("admin/structure/menu/item/$mlid/edit"); danielebarchiesi@2: $menu_attributes = $this->menu_attributes_edit; danielebarchiesi@2: } danielebarchiesi@2: $this->assertResponse(200); danielebarchiesi@2: danielebarchiesi@2: $title = '!link_' . $this->randomName(16); danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'link_path' => $link, danielebarchiesi@2: 'link_title' => $title, danielebarchiesi@2: 'enabled' => TRUE, // Use this to disable the menu and test. danielebarchiesi@2: 'expanded' => TRUE, // Setting this to true should test whether it works when we do the std_user tests. danielebarchiesi@2: 'parent' => $menu_name . ':' . $plid, danielebarchiesi@2: 'weight' => '0', danielebarchiesi@2: 'options[attributes][title]' => $menu_attributes['title'], danielebarchiesi@2: 'options[attributes][id]' => $menu_attributes['id'], danielebarchiesi@2: 'options[attributes][name]' => $menu_attributes['name'], danielebarchiesi@2: 'options[attributes][rel]' => $menu_attributes['rel'], danielebarchiesi@2: 'options[attributes][class]' => $menu_attributes['class'], danielebarchiesi@2: 'options[attributes][style]' => $menu_attributes['style'], danielebarchiesi@2: 'options[attributes][target]' => $menu_attributes['target'], danielebarchiesi@2: 'options[attributes][accesskey]' => $menu_attributes['accesskey'], danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: // Add menu link. danielebarchiesi@2: $this->drupalPost(NULL, $edit, t('Save')); danielebarchiesi@2: danielebarchiesi@2: $item = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(':title' => $title))->fetchAssoc(); danielebarchiesi@2: danielebarchiesi@2: return $item; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function assertMenuAttributes($form_parent, $action = 'new') { danielebarchiesi@2: if ($action == 'new') { danielebarchiesi@2: foreach ($this->menu_attributes_new as $attribute => $value) { danielebarchiesi@2: $this->assertFieldByName($form_parent . '[' . $attribute . ']', $value, t("'$attribute' attribute correct in edit form.")); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: else { danielebarchiesi@2: foreach ($this->menu_attributes_edit as $attribute => $value) { danielebarchiesi@2: $this->assertFieldByName($form_parent . '[' . $attribute . ']', $value, t("New '$attribute' attribute correct in edit form.")); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Test basic functionality. danielebarchiesi@2: */ danielebarchiesi@2: class MenuAttributesTestCase extends MenuAttributesTestHelper { danielebarchiesi@2: public static function getInfo() { danielebarchiesi@2: return array( danielebarchiesi@2: 'name' => 'Menu attributes', danielebarchiesi@2: 'description' => 'Tests menu attributes functionality.', danielebarchiesi@2: 'group' => 'Menu', danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp(array $modules = array()) { danielebarchiesi@2: parent::setUp($modules); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Tests menu attributes functionality. danielebarchiesi@2: */ danielebarchiesi@2: function testMenuAttributes() { danielebarchiesi@2: // Login the user. danielebarchiesi@2: $this->drupalLogin($this->admin_user); danielebarchiesi@2: danielebarchiesi@2: $menu_name = 'navigation'; danielebarchiesi@2: danielebarchiesi@2: // Add a node to be used as a link for menu links. danielebarchiesi@2: $node = $this->drupalCreateNode(array('type' => 'page')); danielebarchiesi@2: danielebarchiesi@2: // Add a menu link. danielebarchiesi@2: $item = $this->crudMenuLink(0, 0, 'node/' . $node->nid, $menu_name); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit'); danielebarchiesi@2: $this->assertMenuAttributes('options[attributes]', 'new'); danielebarchiesi@2: danielebarchiesi@2: // Edit the previously created menu link. danielebarchiesi@2: $item = $this->crudMenuLink($item['mlid'], 0, 'node/' . $node->nid, $menu_name); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit'); danielebarchiesi@2: $this->assertMenuAttributes('options[attributes]', 'edit'); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Test menu attributes settings for nodes. danielebarchiesi@2: */ danielebarchiesi@2: class MenuAttributesNodeTestCase extends MenuAttributesTestHelper { danielebarchiesi@2: public static function getInfo() { danielebarchiesi@2: return array( danielebarchiesi@2: 'name' => 'Menu attributes settings for nodes', danielebarchiesi@2: 'description' => 'Add, edit, and delete a node with menu link.', danielebarchiesi@2: 'group' => 'Menu', danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp(array $modules = array()) { danielebarchiesi@2: parent::setUp($modules); danielebarchiesi@2: $this->drupalLogin($this->admin_user); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Test creating, editing, deleting menu links via node form widget. danielebarchiesi@2: */ danielebarchiesi@2: function testMenuNodeFormWidget() { danielebarchiesi@2: // Enable Navigation menu as available menu. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu_options[navigation]' => 1, danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); danielebarchiesi@2: // Change default parent item to Navigation menu, so we can assert more danielebarchiesi@2: // easily. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu_parent' => 'navigation:0', danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); danielebarchiesi@2: danielebarchiesi@2: // Create a node. danielebarchiesi@2: $node_title = $this->randomName(); danielebarchiesi@2: $language = LANGUAGE_NONE; danielebarchiesi@2: $edit = array( danielebarchiesi@2: "title" => $node_title, danielebarchiesi@2: "body[$language][0][value]" => $this->randomString(), danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('node/add/page', $edit, t('Save')); danielebarchiesi@2: $node = $this->drupalGetNodeByTitle($node_title); danielebarchiesi@2: // Assert that there is no link for the node. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoLink($node_title); danielebarchiesi@2: danielebarchiesi@2: // Edit the node, enable the menu link setting, but skip the link title. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu[enabled]' => 1, danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@2: // Assert that there is no link for the node. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoLink($node_title); danielebarchiesi@2: danielebarchiesi@2: // Edit the node and create a menu link with attributes. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu[enabled]' => 1, danielebarchiesi@2: 'menu[link_title]' => $node_title, danielebarchiesi@2: 'menu[weight]' => 17, danielebarchiesi@2: 'menu[options][attributes][title]' => $this->menu_attributes_new['title'], danielebarchiesi@2: 'menu[options][attributes][id]' => $this->menu_attributes_new['id'], danielebarchiesi@2: 'menu[options][attributes][name]' => $this->menu_attributes_new['name'], danielebarchiesi@2: 'menu[options][attributes][rel]' => $this->menu_attributes_new['rel'], danielebarchiesi@2: 'menu[options][attributes][class]' => $this->menu_attributes_new['class'], danielebarchiesi@2: 'menu[options][attributes][style]' => $this->menu_attributes_new['style'], danielebarchiesi@2: 'menu[options][attributes][target]' => $this->menu_attributes_new['target'], danielebarchiesi@2: 'menu[options][attributes][accesskey]' => $this->menu_attributes_new['accesskey'], danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@2: // Assert that the link exists. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertLink($node_title); danielebarchiesi@2: danielebarchiesi@2: // Assert that the link attributes exist. danielebarchiesi@2: $this->drupalGet('node/' . $node->nid . '/edit'); danielebarchiesi@2: $this->assertMenuAttributes('menu[options][attributes]', 'new'); danielebarchiesi@2: danielebarchiesi@2: // Edit the node again and change the menu link attributes. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu[enabled]' => 1, danielebarchiesi@2: 'menu[link_title]' => $node_title, danielebarchiesi@2: 'menu[weight]' => 17, danielebarchiesi@2: 'menu[options][attributes][title]' => $this->menu_attributes_edit['title'], danielebarchiesi@2: 'menu[options][attributes][id]' => $this->menu_attributes_edit['id'], danielebarchiesi@2: 'menu[options][attributes][name]' => $this->menu_attributes_edit['name'], danielebarchiesi@2: 'menu[options][attributes][rel]' => $this->menu_attributes_edit['rel'], danielebarchiesi@2: 'menu[options][attributes][class]' => $this->menu_attributes_edit['class'], danielebarchiesi@2: 'menu[options][attributes][style]' => $this->menu_attributes_edit['style'], danielebarchiesi@2: 'menu[options][attributes][target]' => $this->menu_attributes_edit['target'], danielebarchiesi@2: 'menu[options][attributes][accesskey]' => $this->menu_attributes_edit['accesskey'], danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@2: danielebarchiesi@2: // Assert that the link attributes exist. danielebarchiesi@2: $this->drupalGet('node/' . $node->nid . '/edit'); danielebarchiesi@2: $this->assertMenuAttributes('menu[options][attributes]', 'edit'); danielebarchiesi@2: danielebarchiesi@2: // Edit the node and remove the menu link. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'menu[enabled]' => FALSE, danielebarchiesi@2: ); danielebarchiesi@2: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@2: // Assert that there is no link for the node. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoLink($node_title); danielebarchiesi@2: } danielebarchiesi@2: }