OptimizelyDefaultSettingsTest.php in Optimizely 8
File
src/Tests/OptimizelyDefaultSettingsTest.php
View source
<?php
namespace Drupal\optimizely\Tests;
use Drupal\simpletest\WebTestBase;
class OptimizelyDefaultSettingsTest extends WebTestBase {
protected $settingsPage = 'admin/config/system/optimizely/settings';
protected $updateDefaultProjPage = 'admin/config/system/optimizely/add_update/1';
protected $optimizelyPermission = 'administer optimizely';
protected $privilegedUser;
public static $modules = [
'optimizely',
];
public static function getInfo() {
return [
'name' => 'Optimizely Default Settings',
'description' => 'Ensure that project settings work correctly',
'group' => 'Optimizely',
];
}
public function setUp() {
parent::setUp();
$this->privilegedUser = $this
->drupalCreateUser([
$this->optimizelyPermission,
]);
}
public function testDefaultSettings() {
$this
->drupalLogin($this->privilegedUser);
$edit = [
'optimizely_id' => rand(0, 10000),
];
$this
->drupalPostForm($this->settingsPage, $edit, t('Submit'));
$optimizely_id = \Drupal::database()
->query('SELECT project_code FROM {optimizely} WHERE oid = 1')
->fetchField();
$this
->assertEqual($optimizely_id, $edit['optimizely_id'], t('<strong>Optimizely ID number added to Default project.</strong>'), 'Optimizely');
$edit = [
'optimizely_enabled' => 1,
];
$this
->drupalPostForm($this->updateDefaultProjPage, $edit, t('Update'));
$enabled = \Drupal::database()
->query('SELECT enabled FROM {optimizely} WHERE oid = 1')
->fetchField();
$this
->assertEqual($enabled, $edit['optimizely_enabled'], t('<strong>The Default project was enabled.</strong>'), 'Optimizely');
$edit = [
'optimizely_enabled' => 0,
];
$this
->drupalPostForm($this->updateDefaultProjPage, $edit, t('Update'));
$enabled = \Drupal::database()
->query('SELECT enabled FROM {optimizely} WHERE oid = 1')
->fetchField();
$this
->assertEqual($enabled, $edit['optimizely_enabled'], t('<strong>The Default project was disabled.</strong>'), 'Optimizely');
}
}