Skip to content

Commit

Permalink
DEV: restructure tests: move controllers
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/controllers/TemplateControllerTest.php
#	tests/functional/admin/InstallationControllerTest.php
  • Loading branch information
TonisOrmisson committed Jan 9, 2018
1 parent 7dadeae commit 63219fa
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 94 deletions.
75 changes: 75 additions & 0 deletions tests/controllers/TemplateControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace ls\tests\controllers;

use ls\tests\DummyController;
use ls\tests\TestBaseClass;

/**
* @since 2017-10-15
* @group tempcontr
* @group template
*/
class TemplateControllerTest extends TestBaseClass
{

/**
* Test copy a template.
* @group copytemplate
*/
public function testCopyTemplate()
{
\Yii::app()->session['loginID'] = 1;
\Yii::import('application.controllers.admin.themes', true);
\Yii::import('application.helpers.globalsettings_helper', true);

// Clean up from last test.
$templateName = 'foobartest';
\TemplateConfiguration::uninstall($templateName);
\Template::model()->deleteAll('name = \'foobartest\'');
\Permission::model()->deleteAllByAttributes(array('permission' => $templateName,'entity' => 'template'));

// Remove folder from last test.
$newname = 'foobartest';
$newdirname = \Yii::app()->getConfig('userthemerootdir') . "/" . $newname;
if (file_exists($newdirname)) {
exec('rm -r ' . $newdirname);
}

$config = require(\Yii::app()->getBasePath() . '/config/config-defaults.php');
// Simulate a POST.
$_POST['newname'] = $newname;
// NB: If default theme is not installed, this test will fail.
$_POST['copydir'] = $config['defaulttheme'];
$_SERVER['SERVER_NAME'] = 'localhost';

$contr = new \themes(new DummyController('dummyid'));
$contr->templatecopy();

$flashes = \Yii::app()->user->getFlashes();
$this->assertEmpty($flashes, 'No flash messages');

$template = \Template::model()->find(
sprintf(
'name = \'%s\'',
$templateName
)
);
$this->assertNotEmpty($template);
$this->assertEquals($templateName, $template->name);



// Clean up. //TODO tearDown
\Template::model()->deleteAll('name = \'foobartest\'');
}

/**
* @todo Copy template folder that does not exist.
*/
/*
public function testCopyWrongFolder()
{
}
*/
}
157 changes: 63 additions & 94 deletions tests/functional/admin/InstallationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,11 @@ class InstallationControllerTest extends TestBaseClassWeb
*/
public static function setupBeforeClass()
{
// NB: Does not call parent, because there might not
// be a database (happens if this test is run multiple
// times).
self::$testHelper = new TestHelper();
self::$webDriver = self::$testHelper->getWebDriver();
self::$domain = getenv('DOMAIN');
}

public static function teardownAfterClass()
{
self::$testHelper->connectToOriginalDatabase();
parent::setUpBeforeClass();
}

/**
*
* @throws \CException
*
*/
public function testBasic()
{
Expand Down Expand Up @@ -93,86 +82,66 @@ public function testBasic()
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
$url = $urlMan->createUrl('');

try {

// Installer start page.
self::$webDriver->get($url);

// Click "Start installation".
$start = self::$webDriver->findElement(WebDriverBy::id('ls-start-installation'));
$start->click();

// Accept license.
$accept = self::$webDriver->findElement(WebDriverBy::id('ls-accept-license'));
$accept->click();

// Click next at pre-check.
$next = self::$webDriver->findElement(WebDriverBy::id('ls-next'));
$next->click();

// Fill in database form.
$dbuserInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbuser]"]'));
$dbpwdInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbpwd]"]'));
$dbnameInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbname]"]'));
$dbuserInput->clear()->sendKeys($dbuser);
$dbpwdInput->clear()->sendKeys($dbpwd);
$dbnameInput->sendKeys($databaseName);

// Click next.
$next = self::$webDriver->findElement(WebDriverBy::id('ls-next'));
$next->click();

// Click "Create database".
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Click "Populate".
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Fill in admin username/password.
$adminLoginName = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginName]"]'));
$adminLoginPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginPwd]"]'));
$confirmPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[confirmPwd]"]'));
$adminLoginName->clear()->sendKeys($username);
$adminLoginPwd->clear()->sendKeys($password);
$confirmPwd->clear()->sendKeys($password);

// Confirm optional settings (admin password etc).
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Go to administration.
$button = self::$webDriver->findElement(WebDriverBy::id('ls-administration'));
$button->click();

// Set debug=2
/* TODO: Can't write to config.php after installation.
$configFile = \Yii::app()->getBasePath() . '/config/config.php';
$data = file($configFile);
$data = array_map(function($data) {
return stristr($data, "'debug'=>0") ? "'debug'=>2," : $data;
}, $data);
$output = [];
exec('chmod 777 ' . $configFile, $output);
var_dump($output);
$result = file_put_contents($configFile, implode('', $data));
$this->assertTrue($result > 0, 'Wrote config');
*/

// Reset urlManager to adapt to latest config.
$config = require($configFile);
$urlMan = \Yii::app()->urlManager;
$urlMan->setUrlFormat($config['components']['urlManager']['urlFormat']);

// Login.
self::adminLogin($username, $password);
} catch (NoSuchElementException $ex) {
self::$testHelper->takeScreenshot(self::$webDriver, (new \ReflectionClass($this))->getShortName() . '_' . __FUNCTION__);
$this->assertFalse(
true,
self::$testHelper->javaTrace($ex)
);
}
// Installer start page.
self::$webDriver->get($url);

// Click "Start installation".
$start = self::$webDriver->findElement(WebDriverBy::id('ls-start-installation'));
$start->click();

// Accept license.
$accept = self::$webDriver->findElement(WebDriverBy::id('ls-accept-license'));
$accept->click();

// Click next at pre-check.
$next = self::$webDriver->findElement(WebDriverBy::id('ls-next'));
$next->click();

// Fill in database form.
$dbuserInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbuser]"]'));
$dbpwdInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbpwd]"]'));
$dbnameInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbname]"]'));
$dbuserInput->clear()->sendKeys($dbuser);
$dbpwdInput->clear()->sendKeys($dbpwd);
$dbnameInput->sendKeys($databaseName);

// Click next.
$next = self::$webDriver->findElement(WebDriverBy::id('ls-next'));
$next->click();

// Click "Create database".
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Click "Populate".
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Fill in admin username/password.
$adminLoginName = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginName]"]'));
$adminLoginPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginPwd]"]'));
$confirmPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[confirmPwd]"]'));
$adminLoginName->clear()->sendKeys($username);
$adminLoginPwd->clear()->sendKeys($password);
$confirmPwd->clear()->sendKeys($password);

// Confirm optional settings (admin password etc).
$button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]'));
$button->click();

// Go to administration.
$button = self::$webDriver->findElement(WebDriverBy::id('ls-administration'));
$button->click();

// Reset urlManager to adapt to latest config.
$configFile = \Yii::app()->getBasePath() . '/config/config.php';
$config = require($configFile);
$urlMan = \Yii::app()->urlManager;
$urlMan->setUrlFormat($config['components']['urlManager']['urlFormat']);

// Login.
self::adminLogin($username, $password);

self::$testHelper->connectToOriginalDatabase();
}
}

0 comments on commit 63219fa

Please sign in to comment.