public function OrderCollectionFilterTest::testCustomerOrderCollectionFiltering in Commerce Core 8.2
Tests filtering orders.
@dataProvider filterDataParameters
File
- modules/
order/ tests/ src/ Kernel/ Jsonapi/ OrderCollectionFilterTest.php, line 81
Class
- OrderCollectionFilterTest
- @group commerce_order
Namespace
Drupal\Tests\commerce_order\Kernel\JsonapiCode
public function testCustomerOrderCollectionFiltering(string $user_type, int $expected_unfiltered_count, array $expected_unfiltered_uuids, int $expected_filtered_count, array $expected_filtered_uuids) {
$user_ids = [
'order_customer' => $this->testOrderCustomer
->id(),
'other_customer' => $this->testOtherCustomer
->id(),
'guest_customer' => 0,
'guest_customer_with_permission' => 0,
'admin_user' => $this
->createUser([], [
'administer commerce_order',
])
->id(),
'view_user' => $this
->createUser([], [
'view commerce_order',
])
->id(),
];
$this
->assertArrayHasKey($user_type, $user_ids);
if ($user_type === 'guest_customer_with_permission') {
$this
->grantPermissions(Role::load(Role::ANONYMOUS_ID), [
'view own commerce_order',
]);
}
$this
->generateTestOrders();
$url = Url::fromRoute('jsonapi.commerce_order--default.collection');
$this->container
->get('session')
->set('uid', $user_ids[$user_type]);
$document = $this
->doRequest($url);
$this
->assertArrayHasKey('data', $document);
$this
->assertCount($expected_unfiltered_count, $document['data'], var_export($document['data'], TRUE));
$this
->assertEquals($expected_unfiltered_uuids, array_map(static function (array $item) {
return $item['id'];
}, $document['data']));
$url
->setOption('query', [
'filter' => [
'state' => 'completed',
],
]);
$document = $this
->doRequest($url);
$this
->assertArrayHasKey('data', $document);
$this
->assertCount($expected_filtered_count, $document['data'], var_export($document['data'], TRUE));
$this
->assertEquals($expected_filtered_uuids, array_map(static function (array $item) {
return $item['id'];
}, $document['data']));
}