Skip to content

Instantly share code, notes, and snippets.

View tamasd's full-sized avatar

Tamás Demeter-Haludka tamasd

  • Lufthansa Systems Hungaria
  • Szeged
View GitHub Profile
class UserTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Administrator user', 'description' => 'an administrator needs to be able to access the admin menu.',
'group' => 'Drucumber',
);
} public function setUp() {
parent::setUp();
$user = $this->drupalCreateUser(array('administer site',));
$this->drupalLogin($user);
func get(path string, cookie *http.Cookie) *http.Response {
req, err := http.NewRequest("GET", BASE_PATH + path, nil)
if err != nil {
log.Fatal(err)
}
req.AddCookie(cookie)
resp, err := http.DefaultClient.Do(req)
if err != nil {
type LoginResponse struct {
SessionID string `json:"sessid"`
SessionName string `json:"session_name"`
}
func login(username, password string) *http.Cookie {
resp := post("user/login", fmt.Sprintf("username=%s&password=%s", url.QueryEscape(username), url.QueryEscape(password)), nil)
if resp.StatusCode != http.StatusCodeOK {
log.Fatal(resp.Status)
}
jsondata := getBody(resp)
var lr LoginResponse
if err := json.Unmarshal(jsondata, &lr); err != nil {
log.Fatal(err)
func getBody(resp *http.Response) []bytes {
respbody, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
return respbody
}
type BodyField struct {
Format string
Value string
}
type Node struct {
Title string
Body map[string][]BodyField
Language string
}
func getNode(nid string, cookie *http.Cookie) (title String, body BodyField) {
resp := get("node/" + nid, cookie)
rawbody := getBody(resp)
var node Node
if err := json.Unmarshal(rawbody, &node); err != nil {
log.Fatal(err)
}
if len(node.Body[node.Language]) > 0 {
return node.Title, node.Body[node.Language][0]
func editBody(original string) string {
tmpfile, err := ioutil.TempFile(os.TempDir(), "myapp")
if err != nil {
log.Fatal(err)
}
name := tmpfile.Name()
tmpfile.WriteString(msg)
tmpfile.Sync()
tmpfile.Close()
func updateNode(nid string, title string, body BodyField, cookie *http.Cookie) {
body.value = editBody(body.value)
postdata := fmt.Sprintf("title=%s&body[und][0][summary]=&body[und][0][value]=%s&body[und][0][format]=%s", url.QueryEscape(title), url.QueryEscape(body.Value), url.QueryEscape(body.Format))
resp := post("node/" + nid, postdata, cookie, "PUT")
if resp.StatusCode != http.StatusOK {
log.Fatal(resp.Status)
}
}
<?php
define('KEXT_DELIMITER', " \t\n");
class KEXT {
public $index;
public $refs;
public $size;
public $wired;
public $name;