<?php
namespace Drupal\shortcut\Tests;
use Drupal\simpletest\WebTestBase;
use stdClass;
abstract class ShortcutTestBase extends WebTestBase {
public static $modules = array(
'toolbar',
'shortcut',
);
protected $admin_user;
protected $shortcut_user;
protected $node;
protected $set;
function setUp() {
parent::setUp();
if ($this->profile != 'standard') {
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Basic page',
));
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
$shortcut_set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
$shortcut_set->links[] = array(
'link_path' => 'node/add',
'link_title' => st('Add content'),
'weight' => -20,
);
$shortcut_set->links[] = array(
'link_path' => 'admin/content',
'link_title' => st('Find content'),
'weight' => -19,
);
shortcut_set_save($shortcut_set);
}
$this->admin_user = $this
->drupalCreateUser(array(
'access toolbar',
'administer shortcuts',
'view the administration theme',
'create article content',
'create page content',
'access content overview',
));
$this->shortcut_user = $this
->drupalCreateUser(array(
'customize shortcut links',
'switch shortcut sets',
));
$this->node = $this
->drupalCreateNode(array(
'type' => 'article',
));
$this
->drupalLogin($this->admin_user);
$this->set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
shortcut_set_assign_user($this->set, $this->admin_user);
}
function generateShortcutSet($title = '', $default_links = TRUE, $set_name = '') {
$set = new stdClass();
$set->title = empty($title) ? $this
->randomName(10) : $title;
if (!empty($set_name)) {
$set->set_name = $set_name;
}
if ($default_links) {
$set->links = array();
$set->links[] = $this
->generateShortcutLink('node/add');
$set->links[] = $this
->generateShortcutLink('admin/content');
}
shortcut_set_save($set);
return $set;
}
function generateShortcutLink($path, $title = '') {
$link = array(
'link_path' => $path,
'link_title' => !empty($title) ? $title : $this
->randomName(10),
);
return $link;
}
function getShortcutInformation($set, $key) {
$info = array();
foreach ($set->links as $link) {
$info[] = $link[$key];
}
return $info;
}
}