Ajoute l'upload d'images

This commit is contained in:
Shikiryu 2017-09-27 08:18:52 +02:00
parent c231b7e26b
commit 9068627e6a

View File

@ -110,7 +110,7 @@ class Account
$crawler = $this->client->request('GET', self::ADD_URL);
file_put_contents(sprintf('%s/add.html', $log_folder), $crawler->html());
$form = $crawler->selectButton('Valider')->form();
$image0 = fopen(sprintf('%s/%s/image0.jpg', DEALS_DIR, $deal->getId()), 'r');
$image0 = sprintf('%s/%s/image0.jpg', DEALS_DIR, $deal->getId());
$fields = $form->getPhpValues();
$fields = array_merge(
$fields,
@ -135,18 +135,15 @@ class Account
'subject' => $deal->getSubject(),
'body' => $deal->getBody(),
'price' => $deal->getPrice(),
'image0' => $image0,
'no_salesmen' => 1,
'phone_hidden' => 1,
]
);
$uri = self::UPLOAD_URL;
$this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
$uri = $form->getUri();
// It needs to be done twice
$this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
$crawler = $this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
// This one doesn't wor either -> redirect to Home
$crawler = $this->client->request('POST', $uri, $fields, ['image0' => $image0]);
file_put_contents(sprintf('%s/upload-3.html', $log_folder), $crawler->html());
$crawler = $this->client->request('POST', $uri, $fields, ['image0' => $image0]);
file_put_contents(sprintf('%s/add-2.html', $log_folder), $crawler->html());
$form = $crawler->selectButton('Valider mon annonce')->form();
$crawler = $this->client->submit($form, ['accept_rule' => 1]);