Skip to content

Commit

Permalink
[Install] provided behat install feature, to test Install module, fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Jan 21, 2018
1 parent 269b58d commit 6b3bb6f
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
36 changes: 36 additions & 0 deletions features/install.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@install
Feature: Yawik installation
In order to start using Yawik
As an administrator
I should able to install yawik application


Background:
Given I don't have "install@example.com" user
And I have install module activated

Scenario: Successfully install yawik
Given I go to the install page
Then I should see "Prerequisites"
When I fill database connection with an active connection
And I fill in "Initial user name" with "install@example.com"
And I fill in "Password" with "test"
And I fill in "Email address for system messages" with "install@example.com"
And I press "Install"
And I wait for the ajax response
Then I should see "\"install@example.com\" was created successfully"
And I should see "The base configuration file was successfully created"
And I should see "Start using YAWIK"

Scenario: Install yawik with empty configuration
Given I go to the install page
And I press "Install"
And I wait for the ajax response
Then I should see "Value is required"

Scenario: Install yawik with invalid database connection
Given I go to the install page
And I fill in "db_conn" with "invalid"
And I press "Install"
And I wait for the ajax response
Then I should see "Invalid connection string"
15 changes: 15 additions & 0 deletions module/Behat/resources/install.module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de>
* @author Anthonius Munthi <me@itstoni.com>
* @since 0.30
*/

return [
'Install'
];
118 changes: 118 additions & 0 deletions module/Behat/src/InstallContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de>
*/

namespace Yawik\Behat;

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\AfterScenarioScope;

/**
* Class InstallContext
*
* @package Yawik\Behat
* @author Anthonius Munthi <me@itstoni.com>
*/
class InstallContext implements Context
{
use CommonContextTrait;

static private $configFile;

static private $yawikGlobalConfig;

static private $yawikBackupConfig;

public function __construct()
{
static::$configFile = getcwd() . '/config/autoload/install.module.php';
static::$yawikGlobalConfig = getcwd() . '/config/autoload/yawik.config.global.php';
static::$yawikBackupConfig = str_replace('yawik.config.global.php', 'yawik.backup', static::$yawikGlobalConfig);
}

/**
* @Given I have install module activated
*/
public function iHaveInstallModuleActivated()
{
$target = static::$configFile;
if(!file_exists($target)){
$source = __DIR__.'/../resources/install.module.php';
copy($source,$target);
chmod($target,0777);
}

// backup existing file
$yawikBackupConfig = static::$yawikBackupConfig;
$yawikGlobalConfig = static::$yawikGlobalConfig;

if(is_file($yawikGlobalConfig)){
rename($yawikGlobalConfig,$yawikBackupConfig);
}
}

/**
* @Given I go to the install page
*/
public function iGoToInstallPage()
{
$url = $this->generateUrl('/');
$url = str_replace('/en','',$url);
$this->visit($url);
}

/**
* @AfterSuite
*/
static public function tearDown()
{
static::restoreConfig();
}

/**
* @AfterScenario
*/
public function afterScenario()
{
static::restoreConfig();
}

/**
* @BeforeSuite
*/
static public function setUp()
{
static::restoreConfig();
}

static public function restoreConfig()
{
if(is_file($file = static::$configFile)){
unlink($file);
}

// restore backup
$yawikBackupConfig = static::$yawikBackupConfig;
$yawikGlobalConfig = static::$yawikGlobalConfig;

if(is_file($yawikBackupConfig)){
rename($yawikBackupConfig,$yawikGlobalConfig);
}
}

/**
* @Given I fill database connection with an active connection
*/
public function iFillActiveConnectionString()
{
$config = $this->getService('config');
$connection = $config['doctrine']['connection']['odm_default']['connectionString'];
$this->minkContext->fillField('db_conn',$connection);
}
}

0 comments on commit 6b3bb6f

Please sign in to comment.