I am using Mink with the Goutte webdriver trying to replace the contents of a form in a website with an XML feed.
I coded the following method:
public function replaceField($field)
{
$baseText = '<?xml version="1.0" encoding="UTF-8"?>
<RiskAssessmentReply xmlns="http://test.com" >
<!-- ExternalId of the Order -->
<OrderId>TO_REPLACE</OrderId>
<RiskInfo>
<Actions>
<SystemAction>SystemAction</SystemAction>
<FinalAction>FinalAction</FinalAction>
</Actions>
<Score SystemScore="0"/>
</RiskInfo>
<!-- One of Accept, Manual_Accept, Reject, Cancel, or Ignore -->
<ResponseCode>Accept</ResponseCode>
<StoreId>TESTSTORE</StoreId>
</RiskAssessmentReply>';
$textWithOrderId = preg_replace('/TO_REPLACE/', $GLOBALS['ORDER_ID'], $baseText);
$this->getSession()->getPage()->fillField($field, $textWithOrderId);
}
Which basically contains the XML feed, then I replace a part of it with an order ID that I have from beforehand and call the function fillField
which comes bundled with Mink.
The problem is that it does not just paste the text that I provide, but formats it in a weird manner by setting backslashes before the " symbols, like this:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
Therefore, when I try to submit the XML feed, the website displays the following error:
| Fatal error: Uncaught exception 'ErrorException' with message 'SimpleXMLElement::__construct(): Entity: line 1: parser error : String not started expecting ' or "'
I've tried using the stripslashes
method from PHP, but it doesn't work, as if I try an echo after adding it an Order ID it displays the original XML without slashes, so I'm guessing there is a calling to some other function when using fillField
that does indeed add the backslashes to my text, but I haven't been able to find the source for it.
Does anyone know where this conversion from "
to \"
is made in order to avoid it?
Thanks
Ensure that you are using stripcslashes instead of stripslashes in the page that receives the form.