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

Test file uploads properly #12

Merged
merged 5 commits into from
Aug 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}

}
Loading