Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform RedisLockFunctionalTest from WTB to BTB #23

Open
wants to merge 8 commits into
base: 8.x-1.x
Choose a base branch
from
Open
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ php:
matrix:
fast_finish: true
allow_failures:
- php: 7
- php: hhvm

env:
Expand Down Expand Up @@ -63,8 +62,8 @@ env:
- DRUPAL_TI_BEHAT_DRIVER="phantomjs"
- DRUPAL_TI_BEHAT_BROWSER="firefox"

# Use Drupal 8.2.x to run tests.
- DRUPAL_TI_CORE_BRANCH="8.2.x"
# Use Drupal 8.3.x to run tests.
- DRUPAL_TI_CORE_BRANCH="8.3.x"

# PHPUnit specific commandline arguments.
- DRUPAL_TI_PHPUNIT_ARGS="--verbose --debug"
Expand All @@ -89,7 +88,7 @@ env:
#- DRUPAL_TI_RUNNERS="phpunit"
#- DRUPAL_TI_RUNNERS="simpletest"
#- DRUPAL_TI_RUNNERS="behat"
- DRUPAL_TI_RUNNERS="phpunit-core simpletest"
- DRUPAL_TI_RUNNERS="phpunit-core"

# This will create the database
mysql:
Expand All @@ -101,8 +100,7 @@ services:
- redis-server

before_install:
- composer self-update
- composer global require "lionsad/drupal_ti:dev-master"
- composer global require "lionsad/drupal_ti:dev-master#396d11d200005eb68491d24170da0a98ae7f51b3"
- drupal-ti before_install

install:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Drupal\redis\Tests;
namespace Drupal\Tests\redis\Functional\Lock;

use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Site\Settings;
use Drupal\system\Tests\Lock\LockFunctionalTest;
use Drupal\Tests\system\Functional\Lock\LockFunctionalTest;

/**
* Confirm locking works between two separate requests.
Expand Down
99 changes: 63 additions & 36 deletions src/Tests/WebTest.php → tests/src/Functional/WebTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

namespace Drupal\redis\Tests;
namespace Drupal\Tests\redis\Functional;

use Drupal\Component\Utility\OpCodeCache;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Site\Settings;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Yaml\Yaml;
use Drupal\Tests\BrowserTestBase;

/**
* Tests complex processes like installing modules with redis backends.
*
* @group redis
*/
class WebTest extends WebTestBase {
class WebTest extends BrowserTestBase {

use FieldUiTestTrait;

Expand All @@ -34,41 +33,56 @@ protected function setUp() {
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->drupalPlaceBlock('local_tasks_block');

$cache_configuration = [
// Set in-memory settings.
$settings = Settings::getAll();
$settings['cache'] = [
'default' => 'cache.backend.redis',
'bins' => [
'config' => 'cache.backend.chainedfast',
'bootstrap' => 'cache.backend.chainedfast',
'discovery' => 'cache.backend.chainedfast',
],
];
$this->settingsSet('cache', $cache_configuration);

$settings['settings']['cache']['default'] = (object) array(
'value' => 'cache.backend.redis',
'required' => TRUE,
);
$settings['settings']['cache']['bins'] = (object) array(
'value' => [
'config' => 'cache.backend.chainedfast',
'bootstrap' => 'cache.backend.chainedfast',
'discovery' => 'cache.backend.chainedfast',
$settings['container_yamls'][] = drupal_get_path('module', 'redis') . '/example.services.yml';

$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'redis.factory' => [
'class' => 'Drupal\redis\ClientFactory',
],
'cache.backend.redis' => [
'class' => 'Drupal\redis\Cache\CacheBackendFactory',
'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
],
'cache.container' => [
'class' => '\Drupal\redis\Cache\PhpRedis',
'factory' => ['@cache.backend.redis', 'get'],
'arguments' => ['container'],
],
'cache_tags_provider.container' => [
'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
'arguments' => ['@redis.factory'],
],
'serialization.phpserialize' => [
'class' => 'Drupal\Component\Serialization\PhpSerialize',
],
],
'required' => TRUE,
);

$this->writeSettings($settings);
];
new Settings($settings);

// Write the containers_yaml update by hand, since writeSettings() doesn't
// support this syntax.
// support some of the definitions.
$filename = $this->siteDirectory . '/settings.php';
chmod($filename, 0666);
$contents = file_get_contents($filename);
$contents .= "\n\n" . '$settings[\'container_yamls\'][] = \'modules/redis/example.services.yml\';';

// Add the container_yaml and cache definition.
$contents .= "\n\n" . '$settings["container_yamls"][] = "' . drupal_get_path('module', 'redis') . '/example.services.yml";';
$contents .= "\n\n" . '$settings["cache"] = ' . var_export($settings['cache'], TRUE) . ';';

// Add the classloader.
$contents .= "\n\n" . '$class_loader->addPsr4(\'Drupal\\\\redis\\\\\', \'' . drupal_get_path('module', 'redis') . '/src\');';

// Add the bootstrap container definition.
$contents .= "\n\n" . '$settings["bootstrap_container_definition"] = ' . var_export($settings['bootstrap_container_definition'], TRUE) . ';';

file_put_contents($filename, $contents);
$settings = Settings::getAll();
$settings['container_yamls'][] = 'modules/redis/example.services.yml';
new Settings($settings);
OpCodeCache::invalidate(DRUPAL_ROOT . '/' . $filename);

// Reset the cache factory.
Expand All @@ -79,6 +93,7 @@ protected function setUp() {
db_drop_table('cache_default');
db_drop_table('cache_render');
db_drop_table('cache_config');
db_drop_table('cache_container');
db_drop_table('cachetags');
db_drop_table('semaphore');
db_drop_table('flood');
Expand All @@ -92,14 +107,25 @@ public function testModuleInstallation() {
$this->drupalLogin($admin_user);

// Enable a few modules.
$edit["modules[Core][node][enable]"] = TRUE;
$edit["modules[Core][views][enable]"] = TRUE;
$edit["modules[Core][field_ui][enable]"] = TRUE;
$edit["modules[Field types][text][enable]"] = TRUE;
$edit["modules[node][enable]"] = TRUE;
$edit["modules[views][enable]"] = TRUE;
$edit["modules[field_ui][enable]"] = TRUE;
$edit["modules[text][enable]"] = TRUE;
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->drupalPostForm(NULL, [], t('Continue'));
$this->assertText('6 modules have been enabled: Field UI, Node, Views, Text, Field, Filter.');
$this->assertFieldChecked('edit-modules-core-field-ui-enable');

$assert = $this->assertSession();

// The order of the modules is not guaranteed, so just assert that they are
// all listed.
$assert->elementTextContains('css', '.messages--status', '6 modules have been enabled');
$assert->elementTextContains('css', '.messages--status', 'Field UI');
$assert->elementTextContains('css', '.messages--status', 'Node');
$assert->elementTextContains('css', '.messages--status', 'Text');
$assert->elementTextContains('css', '.messages--status', 'Views');
$assert->elementTextContains('css', '.messages--status', 'Field');
$assert->elementTextContains('css', '.messages--status', 'Filter');
$assert->checkboxChecked('edit-modules-field-ui-enable');

// Create a node type with a field.
$edit = [
Expand Down Expand Up @@ -144,6 +170,7 @@ public function testModuleInstallation() {
$this->assertFalse(db_table_exists('cache_default'));
$this->assertFalse(db_table_exists('cache_render'));
$this->assertFalse(db_table_exists('cache_config'));
$this->assertFalse(db_table_exists('cache_container'));
$this->assertFalse(db_table_exists('cachetags'));
$this->assertFalse(db_table_exists('semaphore'));
$this->assertFalse(db_table_exists('flood'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace Drupal\redis\Tests\Cache;
namespace Drupal\Tests\redis\Kernel;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\system\Tests\Cache\GenericCacheBackendUnitTestBase;
use Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase;
use Symfony\Component\DependencyInjection\Reference;

/**
* Tests PhpRedis cache backend using GenericCacheBackendUnitTestBase.
*
* @group redis
*/
class PhpRedisUnitTest extends GenericCacheBackendUnitTestBase {
class PhpRedisCacheTest extends GenericCacheBackendUnitTestBase {

/**
* Modules to enable.
Expand All @@ -20,8 +20,8 @@ class PhpRedisUnitTest extends GenericCacheBackendUnitTestBase {
*/
public static $modules = array('system', 'redis');

public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
public function register(ContainerBuilder $container) {
parent::register($container);
// Replace the default checksum service with the redis implementation.
if ($container->has('redis.factory')) {
$container->register('cache_tags.invalidator.checksum', 'Drupal\redis\Cache\RedisCacheTagsChecksum')
Expand Down