Skip to content

Instantly share code, notes, and snippets.

View ygerasimov's full-sized avatar

Yuriy Gerasimov ygerasimov

View GitHub Profile
function testFileCreate() {
$text_file = current($this->drupalGetTestFiles('text'));
$file = new stdClass();
$realpath = realpath($text_file->filename);
$file->filesize = filesize($realpath);
$file->filepath = 'sites/default/files/' . $text_file->basename;
$fh = fopen($realpath, 'r');
$file_data = fread($fh, $file->filesize);
Arguments: <?php array (
'file' =>
stdClass::__set_state(array(
'filesize' => 1024,
'filepath' => 'sites/default/files/text-1.txt',
'file' => 'MTEwMDAxMTEwMTEwMDAwMTEwMDExMTAxMTEwMDAxMTEwMTAxMTAxMTAwMTAwMTAwMDAwMDAxMTEwMTExMTEwCjEwMTExMTAwMTAwMDEwMDAwMTAxMTEwMTAwMTEwMDAwMDExMDExMTEwMTAwMTAwMDAxMTAwMDAwMTEwMTAwMQoxMDAxMDAwMDEwMDEwMTAwMDEwMDEwMDAxMDExMDAwMDExMDEwMTAxMTAxMTExMDExMDAxMTEwMDExMDAxMTEKMDAxMDAwMDAxMTExMTEwMTAwMTExMDEwMDExMTEwMDAwMTAxMTEwMTAxMTExMTAxMTAxMTExMDAwMTEwMDAwCjAxMDAxMDAxMTAwMTExMDExMDExMDAwMDEwMTAwMTAxMTExMTEwMDEwMDAwMDAwMTExMTEwMTEwMTEwMTEwMAoxMTAwMTAxMDEwMDEwMTEwMDExMDExMDEwMTExMTEwMDEwMTAxMDEwMDAwMTExMTAxMTEwMDExMTExMDAxMTAKMDEwMTAwMDExMTEwMDEwMTAwMDAwMDAwMTEwMDEwMTEwMTEwMTAwMDExMTAwMTExMDAxMDEwMTAwMDAxMDExCjAxMTEwMTExMTAxMTExMTExMDAwMTExMDAxMTExMTExMDExMTAwMTAxMDExMTEwMDExMDAwMTAwMDAwMDEwMAoxMTEwMDExMDAxMDAxMTAxMDEwMTAxMDEwMDAwMTAwMDAwMTExMTEwMDAwMDExMTEwMTExMTEwMDAxMDEwMTAKMDExMTEwMTAxMTAwMDAxMDExMDAxMTExMTAwMTAwMTExMTExMDAxMDAwMDEwMDAwMTAwMDAwMDAwMDExMDEwCjAxMTAxM
<?php
// $Id$
/**
* @file
* Call the endpoint tests when no authentication is being used.
*
*/
require_once('ServicesWebTestCase.php') ;
<?php
// $Id$
/**
* Copyright (c) 2010 Madcap BV (http://www.madcap.nl)
* All rights reserved.
*
* Permission is granted for use, copying, modification, distribution,
* and distribution of modified versions of this work as long as the
* above copyright notice is included.
// Get database prefix.
$database_prefix = $GLOBALS['drupal_test_info']['test_run_id'];
// Generate user agent string.
if (preg_match('/simpletest\d+/', $database_prefix, $matches)) {
$user_agent = drupal_generate_test_ua($matches[0]);
}
else {
throw new Exception('Test is not ready to init connection to Webdriver (no database prefix)');
}
@ygerasimov
ygerasimov / gist:9087874
Created February 19, 2014 08:06
Contextual link preprocess taxonomy term
<?php
/**
* Preprocess function.
*/
function example_preprocess_taxonomy_term(&$vars) {
if ($vars['vocabulary_machine_name'] == 'service_category') {
$contextual_links = array(
'#type' => 'contextual_links',
'#contextual_links' => array(
'taxonomy' => array('taxonomy/term', array($vars['tid'])),
<!DOCTYPE html>
<html>
<body>
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
<p>My first paragraph.</p>
@ygerasimov
ygerasimov / gist:6fd45fab43671b8054d3
Created December 23, 2014 11:33
Goutte configuration custom cUrl options
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\MinkContext
- FeatureContext
extensions:
Behat\MinkExtension:
base_url: http://mywebsite.com
goutte:
@ygerasimov
ygerasimov / gist:e59c470b57f903f14359
Created March 5, 2015 15:13
acquia ip_address()
// Code provided by Acquia.
// Non balanced servers (dev and stage) don't have this problem.
if (!empty($conf['reverse_proxy_addresses'])) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ips = array_map('trim', $ips);
// Add REMOTE_ADDR to the X-Forwarded-For list (the ip_address function will
// also do this) in case it's a 10. internal AWS address; if it is we should
// add it to the list of reverse proxy addresses so that ip_address will
// ignore it.
$ips[] = $_SERVER['REMOTE_ADDR'];
var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 4 || phantom.args.length > 5) {
console.log('Usage: viewport.js URL filename sizeX sizeY');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
sizeX = phantom.args[2];