Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev3, m2b: update selenium tests for development3 #1185

Merged
merged 5 commits into from Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions unittests/config_tests_filesender.xml
Expand Up @@ -55,13 +55,20 @@
</testsuite>

<testsuite name="selenium">
<!-- <directory>./selenium/tests</directory> -->

<!--
<file>./selenium/tests/UploadAutoResumeTest.php</file>
<file>./selenium/tests/EncryptionTest.php</file>
<file>./selenium/tests/ConfigurationOptionsTest.php</file>
<file>./selenium/tests/TransferExpiredTest.php</file>


-->
<file>./selenium/tests/InvalidExtensionsTest.php</file>
<file>./selenium/tests/MaxFilesTest.php</file>
<file>./selenium/tests/MaxUploadSizeTest.php</file>
<file>./selenium/tests/TemplatingTest.php</file>
<file>./selenium/tests/HeaderMenuTest.php</file>
<file>./selenium/tests/LanguageSelectTest.php</file>

</testsuite>

<testsuite name="dataset" >
Expand Down
6 changes: 6 additions & 0 deletions unittests/selenium/SeleniumTest.php
Expand Up @@ -862,5 +862,11 @@ public function scrollToTop()
$this->sendKeys($this->byCssSelector(".core"), Keys::HOME);
sleep(2);
}

public function removeUploadStage1( $name )
{
$element = $this->waitForCSS("tr[data-name='".$name."'] .removebutton");
$element->click();
}

}
64 changes: 41 additions & 23 deletions unittests/selenium/tests/HeaderMenuTest.php
Expand Up @@ -6,55 +6,73 @@ class HeaderMenuTest extends SeleniumTest
{

protected $start_url_path = '';


public function testHeaderMenu()
public function testHeaderMenuAuthenticated()
{
extract($this->getKeyBindings());

$this->setupUnauthenticated();
sleep(1);

$this->assertEquals(0, $this->getHeaderMenuSize());

$this->setupAuthenticated();

$this->assertGreaterThanOrEqual( 3, $this->getHeaderMenuSize(),
'authenticated user menu item count' );

$this->setUserPage();

}

public function testHeaderMenuAuthenticatedUserPage()
{
extract($this->getKeyBindings());
$this->assertGreaterThanOrEqual(4, $this->getHeaderMenuSize(),
'user page' );

$this->setAdmin();
}

$this->assertEquals(5, $this->getHeaderMenuSize());


public function testHeaderMenuAdminPage()
{
extract($this->getKeyBindings());
$this->setupAuthenticated();
sleep(3);

$this->assertEquals(10, $this->getHeaderMenuSize());

$this->unsetAdmin();

}

public function testHeaderMenuNoAdminPage()
{
extract($this->getKeyBindings());
$this->setupAuthenticated();

$this->assertGreaterThanOrEqual( 4, $this->getHeaderMenuSize());

$this->unsetUserPage();
}

public function testNormalHeader()
{
extract($this->getKeyBindings());
$this->setupAuthenticated();

$this->assertEquals(3, $this->getHeaderMenuSize());

$this->setupUnauthenticated();
sleep(1);
$this->assertEquals(8, $this->getHeaderMenuSize());


$this->assertEquals(0, $this->getHeaderMenuSize());

$this->setupUnauthenticated();
}

public function testNormalUnauthenticated()
{
extract($this->getKeyBindings());
$this->assertEquals(4, $this->getHeaderMenuSize());
$this->setupAuthenticated();
sleep(1);
}


private function getHeaderMenuSize()
{
$elements = $this->elements($this->using('css selector')->value('.leftmenu ul li'));
$elements = $this->elements($this->using('css selector')->value('#navbarFilesender > .nav-item'));
$count = count($elements);

return $count;
}


}
73 changes: 39 additions & 34 deletions unittests/selenium/tests/InvalidExtensionsTest.php
Expand Up @@ -4,65 +4,70 @@

class InvalidExtensionsTest extends SeleniumTest
{

protected $lastTest = false;
protected $start_url_path = '';


public function testSetup()
{
extract($this->getKeyBindings());
$this->setupAuthenticated();
sleep(4);
$this->assertEquals(1,1,'ok');
}

public function testBat()
{
extract($this->getKeyBindings());

$this->setupAuthenticated();

$this->extensionTest('bat', true);
$this->extensionTest('extensiontest.bat', true);
}


public function testExe()
{
$this->extensionTest('exe', true);
extract($this->getKeyBindings());
$this->setupAuthenticated();
$this->extensionTest('extensiontest.exe', true);
}


public function testAllowedExe()
{
extract($this->getKeyBindings());
$this->setupAuthenticated();
$this->setInvalidExtensions("'somethingelse,somethingother'");

$this->extensionTest('exe', false);

$this->extensionTest('extensiontest.exe', false);
$this->assertEquals(1,1,'ok');
}



public function testInvalidTestExtension()
{
$invalid_file_extension = 'invalidfileextension'.rand(0,100);

$this->setInvalidExtensions("'exe,bat,$invalid_file_extension'");

$this->extensionTest($invalid_file_extension, true);
}

private function extensionTest($file_extension, $ban_expected)
{
$this->lastTest = true;

extract($this->getKeyBindings());

$this->setupAuthenticated();
$this->setInvalidExtensions("'exe,bat,invalidextension55'");

sleep(1);
${"temp"} = $this->execute(array( 'script' => "var file_upload_container = document.getElementsByClassName('file_selector')[0];file_upload_container.style.display='block';", 'args' => array() ));

$test_file = sys_get_temp_dir().DIRECTORY_SEPARATOR.'invalidextension.'.$file_extension;
copy("unittests/selenium/assets/124bytes.txt", $test_file);
$this->sendKeys($this->byCssSelector(".file_selector input[name=\"files\"]"), $test_file);

sleep(1);
$elements = $this->elements($this->using('css selector')->value('*[class="file invalid banned_extension"]'));
$count = count($elements);
$this->extensionTest('extensiontest.invalidextension55', true);
}

$this->assertEquals($ban_expected?1:0, $count);
private function extensionTest($filename, $error_expected)
{
$this->showFileUploader();

$number_of_files = 1;
$fp = $this->addFile( $filename );

//reset
$this->setInvalidExtensions();
$this->waitForFilesListWithPossibleError('.banned_extension', $number_of_files, $error_expected );
}



public function tearDown()
{
if( $this->lastTest ) {
Logger::error("XXX tearDown()" );
$this->setInvalidExtensions();
}
}
}
38 changes: 17 additions & 21 deletions unittests/selenium/tests/LanguageSelectTest.php
Expand Up @@ -5,35 +5,31 @@
class LanguageSelectTest extends SeleniumTest
{

protected $start_url_path = '';

private function selectLangauge( $lang )
{
$this->waitForCSS(".language-dropdown-toggle")->click();
$this->waitForCSS("#toplangdropdown > a[data-id='".$lang."']")->click();
// sleep(5);
}

private function pageText()
{
return $this->byCssSelector("#page .core p")->text();
}

public function testLanguageSelect()
{
extract($this->getKeyBindings());

$this->setupUnauthenticated();

for ($second = 0; ; $second++) {
if ($second >= 60) $this->fail("timeout");
try {
if ($this->byId("language_selector")!=null ? true : false) break;

} catch (Exception $e) {}
sleep(1);
}

$this->select($this->byId("language_selector"))->selectOptionByLabel("nl-nl");

$this->assertContains('FileSender is een veilige manier om bestanden te delen met iedereen!', $this->byCssSelector("#page .box")->text());


$this->select($this->byId("language_selector"))->selectOptionByLabel("English (US)");

$this->assertContains('FileSender is a secure way to share large files with anyone!', $this->byCssSelector("#page .box p")->text());
$this->selectLangauge( 'nl-nl' );
$this->assertContains( 'FileSender is een veilige manier om bestanden te delen met iedereen!',
$this->pageText());

$this->setupAuthenticated();
sleep(3);
$this->selectLangauge( 'en-us' );
$this->assertContains( 'FileSender is a secure way to share large files with anyone!',
$this->pageText());

}

Expand Down
49 changes: 29 additions & 20 deletions unittests/selenium/tests/MaxFilesTest.php
Expand Up @@ -5,53 +5,62 @@
// requires a config
// Config::set( 'max_transfer_files', 30 );


class MaxFilesTest extends SeleniumTest
{

protected $start_url_path = '';
const MAXFILECOUNT = 30;


public function testEnoughFiles()
{
$this->fileQuantityTest(30, false);
$this->fileQuantityTest(self::MAXFILECOUNT, false);

}


public function testTooMuchFiles()
{
$this->fileQuantityTest(31, true);
$this->fileQuantityTest(self::MAXFILECOUNT+1, true);
}

private function fileQuantityTest($number_of_files, $error_expected)
{
$test = $this;
extract($this->getKeyBindings());
$this->setMaxTransferFileCount(self::MAXFILECOUNT);

$this->setupAuthenticated();

${"temp"} = $this->execute(array( 'script' => "var file_upload_container = document.getElementsByClassName('file_selector')[0];file_upload_container.style.display='block';", 'args' => array() ));

$test_files_created = array();
$this->showFileUploader();

$testfiles = array();
for($i = 0; $i < $number_of_files; $i++)
{
$test_file = sys_get_temp_dir().DIRECTORY_SEPARATOR.'no'.($i+1).'.txt';
$test_files_created[] = $test_file;
copy("unittests/selenium/assets/124bytes.txt", $test_file);
$this->sendKeys($this->byCssSelector(".file_selector input[name=\"files\"]"), $test_file);
$fp = $this->addFile( "testseries".$i.".txt" );
$testfiles[] = $fp;
}


$elements = $this->elements($this->using('css selector')->value('*[class="file invalid transfer_too_many_files"]'));
$count = count($elements);

$this->assertEquals($error_expected?1:0, $count);

foreach($test_files_created as $test_file)
{
unlink($test_file);
sleep(2);

if( $error_expected ) {
$this->assertEquals( true,
$this->waitForElementCount('.file.invalid.transfer_too_many_files', 1 ),
"too many files message must be shown for a file" );
} else {
$this->assertEquals( true,
$this->waitForElementCount('.file',$number_of_files),
"all the files are shown in a list" );
$this->assertEquals( true,
$this->waitForElementCount('.file.invalid.transfer_too_many_files', 0 ),
"no files have shown as being too many files" );
}
}


public function tearDown()
{
$this->setMaxTransferFileCount();
$this->setMaxTransferFileSize();
}

}