Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allowed set files for creating HTTP request on client-side #77

Merged
merged 2 commits into from

4 participants

@hason

@jhedstrom Fixes also #76. Can you test please?

@jhedstrom

This does indeed fix #76. Thanks!

@hason

@fabpot This PR works with/without symfony/symfony#5407 (no BC).

@hason

@fabpot Please, can you merge this PR?

@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch hason/file_client (PR #77)
This PR was merged into the master branch.

Commits
-------

3ae1a8c Fixed regression for a cause if upload failed
c05e1f0 Allowed set files for creating HTTP request on client-side

Discussion
----------

Allowed set files for creating HTTP request on client-side

For description see symfony/symfony#4674 (comment)

Related PRs:

https://github.com/Behat/MinkBrowserKitDriver/pull/1
https://github.com/Behat/MinkGoutteDriver/pull/7
symfony/symfony#5407

---------------------------------------------------------------------------

by hason at 2012-09-06T10:55:52Z

@jhedstrom Fixes also #76. Can you test please?

---------------------------------------------------------------------------

by jhedstrom at 2012-09-06T18:15:27Z

This does indeed fix #76. Thanks!

---------------------------------------------------------------------------

by hason at 2012-09-10T07:49:52Z

@fabpot This PR works with/without symfony/symfony#5407 (no BC).

---------------------------------------------------------------------------

by hason at 2012-10-10T09:26:00Z

@fabpot Please, can you merge this PR?
4c192d5
@fabpot fabpot merged commit 3ae1a8c into FriendsOfPHP:master
@arithmetric

There's a fix for a logic error for this functionality in #81.

@craigmarvelley craigmarvelley referenced this pull request from a commit in craigmarvelley/symfony
@fabpot fabpot merged branch hason/crawler (PR #5407)
This PR was merged into the master branch.

Commits
-------

c902966 [DomCrawler] Added ability to set file as raw path to file field

Discussion
----------

[2.2][DomCrawler] Added ability to set file as raw path to file field

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

For description see #4674 (symfony#4674 (comment))

Related PRs:

https://github.com/Behat/MinkBrowserKitDriver/pull/1
https://github.com/Behat/MinkGoutteDriver/pull/7
FriendsOfPHP/Goutte#77

---------------------------------------------------------------------------

by stof at 2012-10-13T21:53:27Z

@fabpot anything missing here ?
0fc0fb3
@LagartoSeb LagartoSeb referenced this pull request from a commit in LagartoSeb/Goutte-test-app
@fabpot fabpot merged branch arithmetric/Goutte-fix_addPostFiles_for_filename_string…
… (PR #81)

This PR was merged into the master branch.

Commits
-------

186e7a1 Adding unit test for a file upload using a specific file name/path rather than a file array with tmp_name.
6c663ac Fixing logic in addPostFiles() to handle when a file name/path string is given in place of the  array.

Discussion
----------

Fixing logic in addPostFiles() to handle when a file name/path string is given in place of the  array.

This is a follow up fix for the change to allow client side file uploads with an arbitrary file name that was recently merged from this PR:
FriendsOfPHP/Goutte#77

The logic in addPostFiles() is not working as expected. When a specific file name is used, it is supplied as a string in $info. This string value in $info passes the check for isset($info['tmp_name']) so I added an additional check using is_array($info).

---------------------------------------------------------------------------

by arithmetric at 2012-10-22T18:27:41Z

Includes a unit test to demonstrate the issue and its solution.
6685f83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 2 deletions.
  1. +8 −2 Goutte/Client.php
  2. +40 −0 Goutte/Tests/ClientTest.php
View
10 Goutte/Client.php
@@ -148,10 +148,16 @@ protected function addPostFiles($request, array $files, $arrayName = '')
$name = $arrayName . '[' . $name . ']';
}
- if (isset($info['tmp_name']) && '' !== $info['tmp_name']) {
- $request->addPostFile($name, $info['tmp_name']);
+ if (isset($info['tmp_name'])) {
+ if ('' !== $info['tmp_name']) {
+ $request->addPostFile($name, $info['tmp_name']);
+ } else {
+ continue;
+ }
} elseif (is_array($info)) {
$this->addPostFiles($request, $info, $name);
+ } else {
+ $request->addPostFile($name, $info);
}
}
}
View
40 Goutte/Tests/ClientTest.php
@@ -146,6 +146,46 @@ public function testUsesPostFilesNestedFields()
), $request->getPostFiles());
}
+ public function testUsesPostFilesOnClientSide()
+ {
+ $guzzle = $this->getGuzzle();
+ $client = new Client();
+ $client->setClient($guzzle);
+ $files = array(
+ 'test' => __FILE__,
+ );
+
+ $crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
+ $request = $this->historyPlugin->getLastRequest();
+
+ $this->assertEquals(array(
+ 'test' => array(
+ new PostFile('test', __FILE__, 'text/x-php')
+ )
+ ), $request->getPostFiles());
+ }
+
+ public function testUsesPostFilesUploadError()
+ {
+ $guzzle = $this->getGuzzle();
+ $client = new Client();
+ $client->setClient($guzzle);
+ $files = array(
+ 'test' => array(
+ 'name' => '',
+ 'type' => '',
+ 'tmp_name' => '',
+ 'error' => 4,
+ 'size' => 0,
+ ),
+ );
+
+ $crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
+ $request = $this->historyPlugin->getLastRequest();
+
+ $this->assertEquals(array(), $request->getPostFiles());
+ }
+
public function testUsesCurlOptions()
{
$guzzle = $this->getGuzzle();
Something went wrong with that request. Please try again.