public function testXSaveAction()
{
//in first case try to create category with invalid name and receive error
$response = $this->request('/roles/categories/xSave', ['name' => $this->invalidCategoryName], 'POST');
$this->assertArrayHasKey('errors', $response);
if ($response['success'] && isset($response['category'])) {
$this->request('/roles/categories/xGroupActionHandler', ['ids' => json_encode([$response['category']['id']])], 'POST');
$this->assertTrue(false, 'Role Category with invalid name creates success without validation errors.');
}
//then create valid category
$response = $this->request('/roles/categories/xSave', ['name' => $this->testCategoryName], 'POST');
$this->assertArrayHasKey('success', $response);
$this->assertArrayHasKey('successMessage', $response);
$this->assertArrayHasKey('category', $response);
$id = $response['category']['id'];
//then try to create category with same name and receive error
$response = $this->request('/roles/categories/xSave', ['name' => $this->testCategoryName], 'POST');
$this->assertArrayHasKey('errors', $response);
if ($response['success'] && isset($response['category'])) {
$this->request('/roles/categories/xGroupActionHandler', ['ids' => json_encode([$response['category']['id']])], 'POST');
$this->assertTrue(false, 'Role Category with duplicate name creates success without validation errors.');
}
//and finally remove this category
$response = $this->request('/roles/categories/xGroupActionHandler', ['ids' => json_encode([$id])], 'POST');
$this->assertArrayHasKey('success', $response);
$this->assertArrayHasKey('successMessage', $response);
}