updated core to 7.58 (right after the site was hacked)

This commit is contained in:
2018-04-20 23:48:40 +02:00
parent 18f4aba146
commit 9344a61b61
711 changed files with 99690 additions and 480 deletions

View File

@@ -0,0 +1,19 @@
name = SimpleTest Example
description = Provides simpletest_example page node type.
package = Example modules
core = 7.x
; Since someone might install our module through Composer, we want to be sure
; that the Drupal Composer facade knows we're specifying a core module rather
; than a project. We do this by namespacing the dependency name with drupal:.
dependencies[] = drupal:simpletest
; Since the namespacing feature is new as of Drupal 7.40, we have to require at
; least that version of core.
dependencies[] = drupal:system (>= 7.40)
files[] = simpletest_example.test
; Information added by Drupal.org packaging script on 2017-01-10
version = "7.x-1.x-dev"
core = "7.x"
project = "examples"
datestamp = "1484076787"

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Install, update and uninstall functions for the simpletest_example module.
*/
/**
* Implements hook_install().
*
* @ingroup simpletest_example
*/
function simpletest_example_install() {
// Ensure the simpletest_example node type is available.
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['simpletest_example']);
}
/**
* Adds a body field to the simpletest_example node type.
*
* @ingroup simpletest_example
*/
function simpletest_example_update_7001() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['simpletest_example']);
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* @file
* Module file for simpletest_example
*/
/**
* @defgroup simpletest_example Example: Simpletest
* @ingroup examples
* @{
* An example of simpletest tests to accompany the tutorial at
* http://drupal.org/node/890654.
*
* This module creates a new node type called 'SimpleTest Example Node Type,'
* so that we can test it.
*/
/**
* Implements hook_node_info().
*/
function simpletest_example_node_info() {
return array(
'simpletest_example' => array(
'name' => t('SimpleTest Example Node Type'),
'base' => 'simpletest_example',
'description' => t('simpletest_example page node type.'),
),
);
}
/**
* Implements hook_permission().
*
* In this case we're adding an addition permission that does the same
* as the one the node module offers, just to demonstrate this error.
*/
function simpletest_example_permission() {
$perms = array();
$perms['extra special edit any simpletest_example'] = array('title' => t('Extra special edit any SimpleTest Example'), 'description' => t('Extra special edit any SimpleTest Example'));
return $perms;
}
/**
* Implements hook_node_access().
*
* Demonstrates a bug that we'll find in our test.
*
* If this is running on the testbot, we don't want the error to show so will
* work around it by testing to see if we're in the 'checkout' directory.
*/
function simpletest_example_node_access($node, $op, $account) {
// Don't get involved if this isn't a simpletest_example node, etc.
$type = is_string($node) ? $node : $node->type;
if ($type != 'simpletest_example' || ($op != 'update' && $op != 'delete')) {
return NODE_ACCESS_IGNORE;
}
// This code has a BUG that we'll find in testing.
//
// This is the incorrect version we'll use to demonstrate test failure.
// The correct version should have ($op == 'update' || $op == 'delete').
// The author had mistakenly always tested with User 1 so it always
// allowed access and the bug wasn't noticed!
if (($op == 'delete') && (user_access('extra special edit any simpletest_example', $account) && ($account->uid == $node->uid))) {
return NODE_ACCESS_ALLOW;
}
return NODE_ACCESS_DENY;
}
/**
* Implements hook_form().
*
* Form for the node type.
*/
function simpletest_example_form($node, $form_state) {
$type = node_type_get_type($node);
$form = array();
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#maxlength' => 255,
'#weight' => -5,
);
}
return $form;
}
/**
* Implements hook_menu().
*
* Provides an explanation.
*/
function simpletest_example_menu() {
$items['examples/simpletest_example'] = array(
'title' => 'Simpletest Example',
'description' => 'Explain the simpletest example and allow the error logic to be executed.',
'page callback' => '_simpletest_example_explanation',
'access callback' => TRUE,
);
return $items;
}
/**
* Returns an explanation of this module.
*/
function _simpletest_example_explanation() {
$explanation = t("This Simpletest Example is designed to give an introductory tutorial to writing
a simpletest test. Please see the <a href='http://drupal.org/node/890654'>associated tutorial</a>.");
return $explanation;
}
/**
* A simple self-contained function used to demonstrate unit tests.
*
* @see SimpletestUnitTestExampleTestCase
*/
function simpletest_example_empty_mysql_date($date_string) {
if (empty($date_string) || $date_string == '0000-00-00' || $date_string == '0000-00-00 00:00:00') {
return TRUE;
}
return FALSE;
}
/**
* @} End of "defgroup simpletest_example".
*/

View File

@@ -0,0 +1,265 @@
<?php
/**
* @file
* An example of simpletest tests to accompany the tutorial at
* http://drupal.org/node/890654.
*/
/**
* The SimpleTestExampleTestCase is a functional test case, meaning that it
* actually exercises a particular sequence of actions through the web UI.
* The majority of core test cases are done this way, but the SimpleTest suite
* also provides unit tests as demonstrated in the unit test case example later
* in this file.
*
* Functional test cases are far slower to execute than unit test cases because
* they require a complete Drupal install to be done for each test.
*
* @see DrupalWebTestCase
* @see SimpleTestUnitTestExampleTestCase
*
* @ingroup simpletest_example
*/
class SimpleTestExampleTestCase extends DrupalWebTestCase {
protected $privilegedUser;
/**
* Give display information to the SimpleTest system.
*
* getInfo() returns a keyed array of information for SimpleTest to show.
*
* It's a good idea to organize your tests consistently using the 'group'
* key.
*/
public static function getInfo() {
return array(
'name' => 'SimpleTest Example',
'description' => 'Ensure that the simpletest_example content type provided functions properly.',
'group' => 'Examples',
);
}
/**
* Set up the test environment.
*
* This method is called once per test method, before the test is executed.
* It gives you a chance to control the setup of the test environment.
*
* If you need a different test environment, then you should create another
* test class which overloads DrupalWebTestCase::setUp() differently.
*
* @see DrupalWebTestCase::setUp()
*/
public function setUp() {
// We call parent::setUp() with the list of modules we want to enable.
// This can be an array or just a list of arguments.
parent::setUp('simpletest_example');
// Create and log in our user. The user has the arbitrary privilege
// 'extra special edit any simpletest_example' which is provided by
// our module to grant access.
$this->privilegedUser = $this->drupalCreateUser(array('create simpletest_example content', 'extra special edit any simpletest_example'));
$this->drupalLogin($this->privilegedUser);
}
/**
* Create a simpletest_example node using the node form.
*/
public function testSimpleTestExampleCreate() {
// Create node to edit.
$edit = array();
$edit['title'] = $this->randomName(8);
$edit["body[und][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/simpletest-example', $edit, t('Save'));
$this->assertText(t('SimpleTest Example Node Type @title has been created.', array('@title' => $edit['title'])));
}
/**
* Create a simpletest_example node and then see if our user can edit it.
*/
public function testSimpleTestExampleEdit() {
$settings = array(
'type' => 'simpletest_example',
'title' => $this->randomName(32),
'body' => array(LANGUAGE_NONE => array(array($this->randomName(64)))),
);
$node = $this->drupalCreateNode($settings);
// For debugging, we might output the node structure with $this->verbose()
// It would only be output if the testing settings had 'verbose' set.
$this->verbose('Node created: ' . var_export($node, TRUE));
// We'll run this test normally, but not on the testbot, as it would
// indicate that the examples module was failing tests.
if (!$this->runningOnTestbot()) {
// The debug() statement will output information into the test results.
// It can also be used in Drupal 7 anywhere in code and will come out
// as a drupal_set_message().
debug('We are not running on the PIFR testing server, so will go ahead and catch the failure.');
$this->drupalGet("node/{$node->nid}/edit");
// Make sure we don't get a 401 unauthorized response:
$this->assertResponse(200, 'User is allowed to edit the content.');
// Looking for title text in the page to determine whether we were
// successful opening edit form.
$this->assertText(t("@title", array('@title' => $settings['title'])), "Found title in edit form");
}
}
/**
* Detect if we're running on PIFR testbot.
*
* Skip intentional failure in that case. It happens that on the testbot the
* site under test is in a directory named 'checkout' or 'site_under_test'.
*
* @return bool
* TRUE if running on testbot.
*/
public function runningOnTestbot() {
// @todo: Add this line back once the testbot variable is available.
// https://www.drupal.org/node/2565181
// return env('DRUPALCI');
return TRUE;
}
}
/**
* Although most core test cases are based on DrupalWebTestCase and are
* functional tests (exercising the web UI) we also have DrupalUnitTestCase,
* which executes much faster because a Drupal install does not have to be
* one. No environment is provided to a test case based on DrupalUnitTestCase;
* it must be entirely self-contained.
*
* @see DrupalUnitTestCase
*
* @ingroup simpletest_example
*/
class SimpleTestUnitTestExampleTestCase extends DrupalUnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'SimpleTest Example unit tests',
'description' => 'Test that simpletest_example_empty_mysql_date works properly.',
'group' => 'Examples',
);
}
/**
* Set up the test environment.
*
* Note that we use drupal_load() instead of passing our module dependency
* to parent::setUp(). That's because we're using DrupalUnitTestCase, and
* thus we don't want to install the module, only load it's code.
*
* Also, DrupalUnitTestCase can't actually install modules. This is by
* design.
*/
public function setUp() {
drupal_load('module', 'simpletest_example');
parent::setUp();
}
/**
* Test simpletest_example_empty_mysql_date().
*
* Note that no environment is provided; we're just testing the correct
* behavior of a function when passed specific arguments.
*/
public function testSimpleTestUnitTestExampleFunction() {
$result = simpletest_example_empty_mysql_date(NULL);
// Note that test assertion messages should never be translated, so
// this string is not wrapped in t().
$message = 'A NULL value should return TRUE.';
$this->assertTrue($result, $message);
$result = simpletest_example_empty_mysql_date('');
$message = 'An empty string should return TRUE.';
$this->assertTrue($result, $message);
$result = simpletest_example_empty_mysql_date('0000-00-00');
$message = 'An "empty" MySQL DATE should return TRUE.';
$this->assertTrue($result, $message);
$result = simpletest_example_empty_mysql_date(date('Y-m-d'));
$message = 'A valid date should return FALSE.';
$this->assertFalse($result, $message);
}
}
/**
* SimpleTestExampleMockModuleTestCase allows us to demonstrate how you can
* use a mock module to aid in functional testing in Drupal.
*
* If you have some functionality that's not intrinsic to the code under test,
* you can add a special mock module that only gets installed during test
* time. This allows you to implement APIs created by your module, or otherwise
* exercise the code in question.
*
* This test case class is very similar to SimpleTestExampleTestCase. The main
* difference is that we enable the simpletest_example_test module in the
* setUp() method. Then we can test for behaviors provided by that module.
*
* @see SimpleTestExampleTestCase
*
* @ingroup simpletest_example
*/
class SimpleTestExampleMockModuleTestCase extends DrupalWebTestCase {
/**
* Give display information to the SimpleTest system.
*
* getInfo() returns a keyed array of information for SimpleTest to show.
*
* It's a good idea to organize your tests consistently using the 'group'
* key.
*/
public static function getInfo() {
return array(
'name' => 'SimpleTest Mock Module Example',
'description' => "Ensure that we can modify SimpleTest Example's content types.",
'group' => 'Examples',
);
}
/**
* Set up the test environment.
*
* Note that we're enabling both the simpletest_example and
* simpletest_example_test modules.
*/
public function setUp() {
// We call parent::setUp() with the list of modules we want to enable.
parent::setUp('simpletest_example', 'simpletest_example_test');
}
/**
* Test modifications made by our mock module.
*
* We create a simpletest_example node and then see if our submodule
* operated on it.
*/
public function testSimpleTestExampleMockModule() {
// Create a user.
$test_user = $this->drupalCreateUser(array('access content'));
// Log them in.
$this->drupalLogin($test_user);
// Set up some content.
$settings = array(
'type' => 'simpletest_example',
'title' => $this->randomName(32),
'body' => array(LANGUAGE_NONE => array(array($this->randomName(64)))),
);
// Create the content node.
$node = $this->drupalCreateNode($settings);
// View the node.
$this->drupalGet("node/{$node->nid}");
// Check that our module did it's thing.
$this->assertText(t('The test module did its thing.'), "Found evidence of test module.");
}
}

View File

@@ -0,0 +1,13 @@
name = "SimpleTest Example Mock Module"
description = "Mock module for the SimpleTest Example module."
package = Example modules
core = 7.x
hidden = TRUE
dependencies[] = simpletest_example
; Information added by Drupal.org packaging script on 2017-01-10
version = "7.x-1.x-dev"
core = "7.x"
project = "examples"
datestamp = "1484076787"

View File

@@ -0,0 +1,31 @@
<?php
/**
* @file
* Implements simpletest_example_test module.
*/
/**
* The mock module for SimpleTest Example.
*
* This module exists so that we can enable it and use it to
* test elements of simpletest_module.
*
* @ingroup simpletest_example
*/
/**
* Implements hook_node_view().
*
* We'll just add some content to nodes of the type we like.
*
* @ingroup simpletest_example
*/
function simpletest_example_test_node_view($node, $view_mode, $langcode) {
if ($node->type == 'simpletest_example') {
$node->content['simpletest_example_test_section'] = array(
'#markup' => t('The test module did its thing.'),
'#weight' => -99,
);
}
}