| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dynamic\Foxy\Parser\Tests\Foxy; |
||
| 4 | |||
| 5 | use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use Dynamic\Foxy\Model\FoxyHelper; |
||
| 7 | use Dynamic\Foxy\Model\Variation; |
||
| 8 | use Dynamic\Foxy\Parser\Foxy\Transaction; |
||
| 9 | use Dynamic\Foxy\Parser\Tests\Controller\DataTestController; |
||
| 10 | use Dynamic\Foxy\Parser\Tests\FoxyXMLFeedFactory; |
||
| 11 | use Dynamic\Foxy\Parser\Tests\Product\FoxyFeedTestProduct; |
||
| 12 | use SilverStripe\Core\Config\Config; |
||
| 13 | use SilverStripe\Dev\FunctionalTest; |
||
| 14 | use SilverStripe\ORM\ArrayList; |
||
| 15 | use SilverStripe\View\ArrayData; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class TransactionTest |
||
| 19 | * @package Dynamic\Foxy\Parser\Tests\Foxy |
||
| 20 | */ |
||
| 21 | class TransactionTest extends FunctionalTest |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected static $fixture_file = '../fixtures.yml'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected static $extra_dataobjects = [ |
||
| 32 | FoxyFeedTestProduct::class, |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * |
||
| 37 | */ |
||
| 38 | protected function setUp() |
||
| 39 | { |
||
| 40 | parent::setUp(); |
||
| 41 | |||
| 42 | Config::modify()->set(Variation::class, 'has_one', ['Product' => FoxyFeedTestProduct::class]); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @throws \SilverStripe\Security\PasswordEncryptor_NotFoundException |
||
| 47 | */ |
||
| 48 | protected static function get_foxy_data() |
||
| 49 | { |
||
| 50 | $password = 'password'; |
||
| 51 | $hashType = 'sha1_v2.4'; |
||
| 52 | $salt = 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt'; |
||
| 53 | |||
| 54 | return [ |
||
| 55 | "TransactionDate" => strtotime("now"), |
||
| 56 | "OrderID" => rand(0, 5000), |
||
| 57 | "Email" => FoxyXMLFeedFactory::generate_email(), |
||
| 58 | "Password" => FoxyXMLFeedFactory::get_hashed_password($hashType, $password, $salt), |
||
| 59 | 'Salt' => $salt, |
||
| 60 | 'HashType' => $hashType, |
||
| 61 | "OrderDetails" => ArrayData::create([ |
||
| 62 | 'Title' => 'foo', |
||
| 63 | 'Price' => 20.00, |
||
| 64 | 'Quantity' => 1, |
||
| 65 | 'Weight' => 0.1, |
||
| 66 | 'DeliveryType' => 'shipped', |
||
| 67 | 'CategoryDescription' => 'Default cateogry', |
||
| 68 | 'CategoryCode' => 'DEFAULT', |
||
| 69 | 'Options' => [ |
||
| 70 | [ |
||
| 71 | 'Name' => 'color', |
||
| 72 | 'OptionValue' => 'blue', |
||
| 73 | 'PriceMod' => '', |
||
| 74 | 'WeightMod' => '', |
||
| 75 | ], |
||
| 76 | [ |
||
| 77 | 'Name' => 'product_id', |
||
| 78 | 'OptionValue' => 5, |
||
| 79 | 'PriceMod' => '', |
||
| 80 | 'WeightMod' => '', |
||
| 81 | ], |
||
| 82 | ], |
||
| 83 | ]), |
||
| 84 | ]; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @throws \Exception |
||
| 89 | */ |
||
| 90 | public static function setUpBeforeClass() |
||
| 91 | { |
||
| 92 | parent::setUpBeforeClass(); |
||
| 93 | |||
| 94 | Config::modify()->set(FoxyHelper::class, 'secret', 'abc123'); |
||
| 95 | Config::modify()->merge(DataTestController::class, 'allowed_actions', ['index', 'xml', 'encryptedXML']); |
||
| 96 | Config::modify()->set(DataTestController::class, 'data', static::get_foxy_data()); |
||
| 97 | Config::modify()->set(DataTestController::class, 'run_config_update', false); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * |
||
| 102 | */ |
||
| 103 | public function testTransactionConstruct() |
||
| 104 | { |
||
| 105 | $response = $this->get('/foxytest/xml'); |
||
| 106 | |||
| 107 | if (PHP_VERSION_ID < 70100) { |
||
| 108 | $this->markTestSkipped('PHPUnit_Framework_Error_Warning exception is thrown for legacy PHP versions only'); |
||
| 109 | } else { |
||
| 110 | $this->expectException(\ArgumentCountError::class); |
||
| 111 | } |
||
| 112 | |||
| 113 | Transaction::create(); |
||
| 114 | |||
| 115 | $this->assertInstanceOf(Transaction::class, Transaction::create($response)); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @throws \SilverStripe\ORM\ValidationException |
||
| 120 | * @throws \SilverStripe\Security\PasswordEncryptor_NotFoundException |
||
| 121 | */ |
||
| 122 | public function testGetParsedTransactionData() |
||
| 123 | { |
||
| 124 | $response = DataTestController::singleton()->encryptedXML(); |
||
| 125 | |||
| 126 | $this->assertInstanceOf(ArrayData::class, Transaction::create($response)->getParsedTransactionData()); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @throws \SilverStripe\ORM\ValidationException |
||
| 131 | * @throws \SilverStripe\Security\PasswordEncryptor_NotFoundException |
||
| 132 | */ |
||
| 133 | public function testAttributesExist() |
||
| 134 | { |
||
| 135 | $response = DataTestController::singleton()->encryptedXML(); |
||
| 136 | $transaction = Transaction::create($response)->getParsedTransactionData(); |
||
| 137 | |||
| 138 | $this->assertInstanceOf(ArrayList::class, $transaction->products); |
||
| 139 | $this->assertInstanceOf(ArrayList::class, $transaction->discounts); |
||
| 140 | } |
||
| 141 | } |
||
| 142 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths