* Use christophwurst/nextcloud_testing
* Move selenium test framwork to testing lib
* Make sure all test classes are based on the test lib's test case

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2018-02-19 15:54:46 +01:00
Родитель 2973ba38c3
Коммит 1da05b34b7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CC42AC2A7F0E56D8
7 изменённых файлов: 1419 добавлений и 175 удалений

Просмотреть файл

@ -7,7 +7,7 @@
"php": ">=7.0.0"
},
"require-dev": {
"facebook/webdriver": "^1.5.0"
"christophwurst/nextcloud_testing": "0.2.0"
},
"config": {
"optimize-autoloader": true,

1442
composer.lock сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,105 +0,0 @@
<?php
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* Two-factor TOTP
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\TwoFactorTOTP\Tests\Acceptance;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\WebDriverBrowserType;
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
use GuzzleHttp\Client;
use PHPUnit_Framework_TestCase;
abstract class AcceptanceTest extends PHPUnit_Framework_TestCase {
/** @var RemoteWebDriver */
protected $webDriver;
protected function setUp() {
parent::setUp();
$capabilities = [
WebDriverCapabilityType::BROWSER_NAME => $this->getBrowser(),
];
if ($this->isRunningOnCI()) {
$capabilities['tunnel-identifier'] = getenv('TRAVIS_JOB_NUMBER');
$capabilities['build'] = getenv('TRAVIS_BUILD_NUMBER');
$capabilities['name'] = $this->getTestName();
$user = getenv('SAUCE_USERNAME');
$accessKey = getenv('SAUCE_ACCESS_KEY');
$this->webDriver = RemoteWebDriver::create("http://$user:$accessKey@ondemand.saucelabs.com/wd/hub", $capabilities);
} else {
$user = getenv('SAUCE_USERNAME');
$accessKey = getenv('SAUCE_ACCESS_KEY');
$this->webDriver = RemoteWebDriver::create("http://$user:$accessKey@localhost:4445/wd/hub", $capabilities);
}
}
private function getBrowser() {
$fromEnv = getenv('SELENIUM_BROWSER');
if ($fromEnv !== false) {
return $fromEnv;
}
return WebDriverBrowserType::FIREFOX;
}
private function getTestName() {
if ($this->isRunningOnCI()) {
return 'PR' . getenv('TRAVIS_PULL_REQUEST') . ', Build ' . getenv('TRAVIS_BUILD_NUMBER') . ', Test ' . self::class . '::' . $this->getName();
} else {
return 'Test ' . self::class . '::' . $this->getName();
}
}
protected function tearDown() {
parent::tearDown();
$sessionId = $this->webDriver->getSessionID();
$this->webDriver->quit();
if ($this->isRunningOnCI()) {
$this->reportTestStatusToSauce($sessionId);
}
}
/**
* @param string $sessionId sauce labs job id
*/
private function reportTestStatusToSauce($sessionId) {
$failed = parent::hasFailed();
$httpClient = new Client();
$httpClient->put("https://saucelabs.com/rest/v1/nextcloud-totp/jobs/$sessionId", [
'auth' => [
getenv('SAUCE_USERNAME'),
getenv('SAUCE_ACCESS_KEY'),
],
'json' => [
'passed' => !$failed,
],
]);
}
private function isRunningOnCI() {
return getenv('TRAVIS') !== false;
}
}

Просмотреть файл

@ -23,6 +23,9 @@
namespace OCA\TwoFactorTOTP\Tests\Acceptance;
use Base32\Base32;
use ChristophWurst\Nextcloud\Testing\Selenium;
use ChristophWurst\Nextcloud\Testing\TestCase;
use ChristophWurst\Nextcloud\Testing\TestUser;
use Facebook\WebDriver\Exception\ElementNotSelectableException;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
@ -40,7 +43,10 @@ use PHPUnit_Framework_AssertionFailedError;
/**
* @group Acceptance
*/
class TOTPAcceptenceTest extends AcceptanceTest {
class TOTPAcceptenceTest extends TestCase {
use TestUser;
use Selenium;
/** @var IUser */
private $user;
@ -51,27 +57,8 @@ class TOTPAcceptenceTest extends AcceptanceTest {
public function setUp() {
parent::setUp();
$this->user = OC::$server->getUserManager()->get('admin');
$this->user = $this->createTestUser();
$this->secretMapper = new TotpSecretMapper(OC::$server->getDatabaseConnection());
$this->cleanUp();
}
protected function tearDown() {
parent::tearDown();
$this->cleanUp();
}
private function cleanUp() {
// Always delete secret again
try {
$secret = $this->secretMapper->getSecret($this->user);
if (!is_null($secret)) {
$this->secretMapper->delete($secret);
}
} catch (DoesNotExistException $ex) {
// Ignore
}
}
public function testEnableTOTP() {
@ -79,8 +66,8 @@ class TOTPAcceptenceTest extends AcceptanceTest {
$this->assertContains('Nextcloud', $this->webDriver->getTitle());
// Log in
$this->webDriver->findElement(WebDriverBy::id('user'))->sendKeys('admin');
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys('admin');
$this->webDriver->findElement(WebDriverBy::id('user'))->sendKeys($this->user->getUID());
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys('password');
$this->webDriver->findElement(WebDriverBy::cssSelector('form[name=login] input[type=submit]'))->click();
// Go to personal settings and TOTP settings
@ -157,8 +144,8 @@ class TOTPAcceptenceTest extends AcceptanceTest {
$this->assertContains('Nextcloud', $this->webDriver->getTitle());
// Log in
$this->webDriver->findElement(WebDriverBy::id('user'))->sendKeys('admin');
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys('admin');
$this->webDriver->findElement(WebDriverBy::id('user'))->sendKeys($this->user->getUID());
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys('password');
$this->webDriver->findElement(WebDriverBy::cssSelector('form[name=login] input[type=submit]'))->click();
$this->webDriver->wait(20, 200)->until(function(WebDriver $driver) {

Просмотреть файл

@ -22,6 +22,7 @@
namespace OCA\TwoFactorTOTP\Test\Unit\Activity;
use ChristophWurst\Nextcloud\Testing\TestCase;
use InvalidArgumentException;
use OCA\TwoFactorTOTP\Activity\Provider;
use OCP\Activity\IEvent;
@ -29,7 +30,6 @@ use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use Test\TestCase;
class ProviderTest extends TestCase {

Просмотреть файл

@ -22,9 +22,9 @@
namespace OCA\TwoFactorTOTP\Test\Unit\Activity;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\TwoFactorTOTP\Activity\Setting;
use OCP\IL10N;
use Test\TestCase;
class SettingTest extends TestCase {

Просмотреть файл

@ -31,9 +31,9 @@ use OCP\Defaults;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
class SettingsControllerTest extends PHPUnit_Framework_TestCase {
class SettingsControllerTest extends TestCase {
private $request;
private $userSession;