<?php

/**
 * Copyright 06.04.2016 Victoria Speckmann-Bresges
 */
use Trifledev\Feefo\Api\FeefoSendBulkSale;
$feefoInform = new FeefoSendBulkSale($domain);
$feefoInform->setExportStoragePath(__DIR__ . '/../orders');
$entries = [];
$errors = [];
$success = '';
$isFileValid = false;
$hasConfirmed = false;
$prepResult = [];
// set currency form select options
$formCurrencies = ['GBP' => '&pound; Pound', 'EUR' => '&euro; Euro', 'USD' => '&#36; U.S. Dollar'];
if (isset($_POST['bulk_feefo_order_upload']) || isset($_POST['bulk_feefo_order_upload_confirm'])) {
    $hasConfirmed = isset($_POST['bulk_feefo_order_upload_confirm']) && $_POST['hasConfirmed'] === 'true';
    if (!$hasConfirmed) {
        $prepResult = $feefoInform->prepareBulkOrder($_FILES['import_file']);
        $isFileValid = !empty($prepResult);
        if (!$isFileValid) {
            $errors = $feefoInform->getValidator()->getValidationErrors();
        } else {
            $entries = $prepResult['orders'];
        }
    }
    if ($hasConfirmed) {
        $result = $feefoInform->sendBulkOrderFile($_POST['filename']);
        if ($result) {
            $success = 'Order(s) successfully uploaded';
 public function testStoreOrdersToFile()
 {
     $testData = ['name' => 'Product name', 'email' => 'Customer email', 'date' => 'Todays date', 'description' => 'Example description', 'logon' => 'www.examplesupplier.com', 'category' => 'category1', 'product_search_code' => 'Example name', 'order_ref' => 'Prod-internal-id', 'product_link' => 'http://www.examplesupplier.com/products/133', 'customer_ref' => 'Cust-internal-id'];
     $this->assertContainsOnly('boolean', $this->_sendBulkSale->storeOrdersToFile($testData));
 }