Skip to content

Commit

Permalink
Merge pull request #12 from alexpott/TASK-do-not-map-files-to-selenium
Browse files Browse the repository at this point in the history
Test file uploads properly
  • Loading branch information
justafish authored Aug 8, 2024
2 parents 4f679e6 + 58e70d9 commit 145fe8e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"php": ">=8.1",
"ext-json": "*",
"behat/mink": "^1.11@dev",
"lullabot/php-webdriver": "^2.0.5"
"lullabot/php-webdriver": "^2.0.6"
},
"require-dev": {
"mink/driver-testsuite": "dev-master",
Expand Down
48 changes: 48 additions & 0 deletions tests/Custom/RemoteFileUploadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Behat\Mink\Tests\Driver\Custom;

use Behat\Mink\Tests\Driver\TestCase;
use Composer\InstalledVersions;

class RemoteFileUploadTest extends TestCase
{
public function testRemoteFileUpload(): void
{
$this->getSession()->visit($this->pathTo('/advanced_form.html'));

$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage();

$about = $webAssert->fieldExists('about');
// Place a file outside of the directories mapped to the selenium
// server.
$path = sys_get_temp_dir() . '/some_file.txt';
copy(InstalledVersions::getInstallPath('mink/driver-testsuite') . '/web-fixtures/some_file.txt', $path);
$about->attachFile($path);
unlink(sys_get_temp_dir() . '/some_file.txt');

$button = $page->findButton('Register');
$this->assertNotNull($button);
$button->press();

if ($this->safePageWait(5000, 'document.title === "Advanced form save"')) {
$out = <<<'OUT'
some_file.txt
1 uploaded file
OUT;
$this->assertStringContainsString($out, $page->getContent());
}
else {
$this->fail('Failed to submit form');
}
}

protected function tearDown(): void
{
if (file_exists(sys_get_temp_dir() . '/some_file.txt')) {
unlink(sys_get_temp_dir() . '/some_file.txt');
}
}

}

0 comments on commit 145fe8e

Please sign in to comment.