enhancements to pre and post conditions

This commit is contained in:
Sergio Bertolin 2015-11-03 16:08:01 +00:00
parent b0c456c0fc
commit 0f27b719ea
1 changed files with 60 additions and 0 deletions

View File

@ -30,6 +30,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var array */ /** @var array */
private $createdUsers = []; private $createdUsers = [];
/** @var array */
private $createdGroups = [];
public function __construct($baseUrl, $admin, $regular_user_password) { public function __construct($baseUrl, $admin, $regular_user_password) {
// Initialize your context here // Initialize your context here
@ -354,23 +357,35 @@ class FeatureContext implements Context, SnippetAcceptingContext {
} }
public function createUser($user) { public function createUser($user) {
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->creatingTheUser($user); $this->creatingTheUser($user);
$this->userExists($user); $this->userExists($user);
$this->currentUser = $previous_user;
} }
public function deleteUser($user) { public function deleteUser($user) {
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->deletingTheUser($user); $this->deletingTheUser($user);
$this->userDoesNotExist($user); $this->userDoesNotExist($user);
$this->currentUser = $previous_user;
} }
public function createGroup($group) { public function createGroup($group) {
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->creatingTheGroup($group); $this->creatingTheGroup($group);
$this->groupExists($group); $this->groupExists($group);
$this->currentUser = $previous_user;
} }
public function deleteGroup($group) { public function deleteGroup($group) {
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->deletingTheGroup($group); $this->deletingTheGroup($group);
$this->groupDoesNotExist($group); $this->groupDoesNotExist($group);
$this->currentUser = $previous_user;
} }
public function creatingTheUser($user) { public function creatingTheUser($user) {
@ -388,6 +403,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
$this->createdUsers[$user] = $user; $this->createdUsers[$user] = $user;
echo "Creating a user inside creatingTheuser\n";
} }
/** /**
@ -406,6 +422,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
]; ];
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
$this->createdGroups[$group] = $group;
} }
/** /**
@ -603,6 +620,38 @@ class FeatureContext implements Context, SnippetAcceptingContext {
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
public static function createTextFile($path, $filename){
$myfile = fopen("$path" . "$filename", "w") or die("Unable to open file!");
$txt = "ownCloud test text file\n";
fwrite($myfile, $txt);
fclose($myfile);
}
public static function removeFile($path, $filename){
if (file_exists("$path" . "$filename")) {
unlink("$path" . "$filename");
}
}
/**
* @BeforeSuite
*/
public static function addFilesToSkeleton(){
for ($i=0; $i<5; $i++){
self::createTextFile("../../core/skeleton/", "textfile" . "$i" . ".txt");
}
}
/**
* @AfterSuite
*/
public static function removeFilesFromSkeleton(){
for ($i=0; $i<5; $i++){
self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt");
}
}
/** /**
* @BeforeScenario * @BeforeScenario
* @AfterScenario * @AfterScenario
@ -614,4 +663,15 @@ class FeatureContext implements Context, SnippetAcceptingContext {
} }
} }
/**
* @BeforeScenario
* @AfterScenario
*/
public function cleanupGroups()
{
foreach($this->createdGroups as $group) {
$this->deleteGroup($group);
}
}
} }