public function PatternsShortcutTestCase::test_shortcut in Patterns 7
Same name and namespace in other branches
- 7.2 tests/shortcut/shortcut.test \PatternsShortcutTestCase::test_shortcut()
Test the:
- add a new set 'new_set_fortest'
- add a new shortcut link to the new set 'new_set_fortest' which add before
- edit the link, which add before
- switch set for user
- delete the link, which just edit
- change the set "new_set_fortest" name to "newer_set_fortest"
- delete the set "newer_set_fortest"
File
- tests/
shortcut/ shortcut.test, line 77 - SimpleTests for the Shortcut component of Patterns.
Class
- PatternsShortcutTestCase
- @file SimpleTests for the Shortcut component of Patterns.
Code
public function test_shortcut() {
//for add a new set 'new_set_fortest'
parent::runFile('shortcut_add_set.yaml', 'add new shortcut set (create)', $this->shortcut_tests_dir);
$query_add_set = db_select('shortcut_set', 'ss')
->fields('ss', array(
'set_name',
'title',
))
->condition('ss.title', 'new_set_fortest')
->execute()
->fetchAssoc();
$this
->assertTrue($query_add_set, t('Adding a new set \'new_set_fortest\' works fine.'));
$num = count($query_add_set);
$this
->assert('pass', 'the num of query db is ' . $num);
foreach ($query_add_set as $key => $value) {
$this
->assert('pass', $key . ' is ' . $value);
}
$this
->drupalGet('admin/config/user-interface/shortcut');
$this
->assertResponse(200);
$this
->assertRaw('<td>new_set_fortest</td>', t('new_set_fortest is built successful.'));
//for add a new shortcut link to the new set which add before
parent::runFile('shortcut_add_link.yaml', 'add a link to a shortcut set (create)', $this->shortcut_tests_dir);
$query = db_select('menu_links', 'ml')
->fields('ml', array(
'menu_name',
'mlid',
'link_path',
'link_title',
))
->condition('ml.menu_name', $query_add_set['set_name'])
->condition('ml.link_title', 'link_admcont')
->condition('ml.link_path', 'admin/content')
->execute()
->fetchAssoc();
$this
->assertTrue($query, t('Adding shortcut link works fine.'));
$num = count($query);
$this
->assert('pass', 'the num of query db is ' . $num);
foreach ($query as $key => $value) {
$this
->assert('pass', $key . ' is ' . $value);
}
$this
->drupalGet('admin/config/user-interface/shortcut/' . $query_add_set['set_name']);
$this
->assertResponse(200);
$this
->assertRaw('admin/content">link_admcont</a></td>', t('the new link:link_admcont(admin/content) is built successful.'));
//for edit the link, which add before
parent::runFile('shortcut_edit_link.yaml', 'edit a link of a shortcut set (modify)', $this->shortcut_tests_dir);
$query = db_select('menu_links', 'ml')
->fields('ml', array(
'menu_name',
'mlid',
'link_path',
'link_title',
))
->condition('ml.menu_name', $query_add_set['set_name'])
->condition('ml.link_title', 'link_nodadd')
->condition('ml.link_path', 'node/add')
->execute()
->fetchAssoc();
$this
->assertTrue($query, t('Edit shortcut link works fine.'));
$num = count($query);
$this
->assert('pass', 'the num of query db is ' . $num);
foreach ($query as $key => $value) {
$this
->assert('pass', $key . ' is ' . $value);
}
$this
->drupalGet('admin/config/user-interface/shortcut/' . $query_add_set['set_name']);
$this
->assertResponse(200);
$this
->assertNoRaw('admin/content">link_admcont</a></td>', t('the old link:link_adncont(admin/content) has changed.'));
$this
->assertRaw('node/add">link_nodadd</a></td>', t('the new link:link_nodadd(node/add) has been built successful.'));
//for switch user's shortcut set
parent::runFile('shortcut_set_switch.yaml', 'switch shortcut set for users (modify)', $this->shortcut_tests_dir);
$queryuser = db_select('users', 'u')
->fields('u', array(
'uid',
))
->condition('u.name', 'someone')
->execute()
->fetchField();
$query = db_select('shortcut_set_users', 'ssu')
->fields('ssu', array(
'set_name',
'uid',
))
->condition('ssu.uid', $queryuser)
->condition('ssu.set_name', $query_add_set['set_name'])
->execute()
->fetchAssoc();
$this
->assertTrue($query, t('Switching user\'s shortcut set works fine.'));
$num = count($query);
$this
->assert('pass', 'the num of query db is ' . $num);
foreach ($query as $key => $value) {
$this
->assert('pass', $key . ' is ' . $value);
}
$this
->drupalGet('user/' . $queryuser . '/shortcuts');
$this
->assertResponse(200);
$this
->assertRaw('value="' . $query_add_set['set_name'] . '" checked="checked"', t('user "someone"\'s shortcut_set is ' . $query_add_set['title'] . ' now'));
//TODO it seems the toolbar and shortcut can not be enabled in the simpletest, why?
//$this->assertRaw('node/add">link_nodadd</a></li>', t('user "someone"\'s shortcut_set has the link_nodadd now'));
//for delete the link, which just edit
parent::runFile('shortcut_delete_link.yaml', 'delete a link from a shortcut set (modify)', $this->shortcut_tests_dir);
$query = db_select('menu_links', 'ml')
->fields('ml', array(
'menu_name',
'mlid',
'link_path',
'link_title',
))
->condition('ml.menu_name', $query_add_set['set_name'])
->condition('ml.link_title', 'link_nodadd')
->condition('ml.link_path', 'node/add')
->execute()
->fetchAssoc();
$this
->assertFalse($query, t('Delete shortcut link works fine.'));
$this
->drupalGet('admin/config/user-interface/shortcut/' . $query_add_set['set_name']);
$this
->assertResponse(200);
$this
->assertNoRaw('node/add">link_nodadd</a></td>', t('the new link:link_nodadd(node/add) has been deleted.'));
//for change the set "new_set_fortest" name to "newer_set_fortest"
parent::runFile('shortcut_edit_set.yaml', 'edit the shortcut set name(modify)', $this->shortcut_tests_dir);
$query = db_select('shortcut_set', 'ss')
->fields('ss', array(
'set_name',
'title',
))
->condition('ss.title', 'newer_set_fortest')
->condition('ss.set_name', $query_add_set['set_name'])
->execute()
->fetchAssoc();
$this
->assertTrue($query, t('Editing set works fine.'));
$num = count($query);
$this
->assert('pass', 'the num of query db is ' . $num);
foreach ($query as $key => $value) {
$this
->assert('pass', $key . ' is ' . $value);
}
$this
->drupalGet('admin/config/user-interface/shortcut');
$this
->assertResponse(200);
$this
->assertRaw('<td>newer_set_fortest</td>', t('new_set_fortest has been changed to newer_set_fortest.'));
//for delete the set, which add before
parent::runFile('shortcut_delete_set.yaml', 'delete a shortcut set (delete)', $this->shortcut_tests_dir);
$query = db_select('shortcut_set', 'ss')
->fields('ss', array(
'set_name',
'title',
))
->condition('ss.title', 'newer_set_fortest')
->condition('ss.set_name', $query_add_set['set_name'])
->execute()
->fetchAssoc();
$this
->assertFalse($query, t('Deleting set works fine.'));
$this
->drupalGet('admin/config/user-interface/shortcut');
$this
->assertResponse(200);
$this
->assertNoRaw('<td>newer_set_fortest</td>', t('newer_set_fortest has been deleted.'));
$this
->drupalGet('user/' . $queryuser . '/shortcuts');
$this
->assertResponse(200);
}