public function AcquiaLiftTest::testSaveDecisionSet in Acquia Lift Connector 7.2
Test AcquiaLiftAPI->saveDecisionSet()
File
- tests/
AcquiaLiftAPI.test, line 149 - Unit tests for Acquia Lift module.
Class
- AcquiaLiftTest
- @file Unit tests for Acquia Lift module.
Code
public function testSaveDecisionSet() {
$lift_api = $this
->getAcquiaLiftAPI();
$name = 'some-test-decision';
$title = 'Some Test Decision';
$options = array(
array(
'option_id' => 'option-1',
),
array(
'option_id' => 'option-2',
),
);
$lift_api
->saveDecisionSet($name, $title, $options);
$logged_requests = DummyAcquiaLiftHttpClient::getLoggedRequests();
$expected_uri = "{$lift_api->getApiUrl()}/decision_sets?client_id={$lift_api->getPublicKey()}";
$expected_body = json_encode(array(
"id" => "some-test-decision",
"title" => "Some Test Decision",
"decisions" => array(
array(
"external_id" => "option-1",
),
array(
"external_id" => "option-2",
),
),
));
// Confirm the request URI and body are as expected.
$this
->assertAPIRequestURI($expected_uri, $logged_requests[0]['uri']);
$this
->assertEqual($expected_body, $logged_requests[0]['body']);
$logs = array(
array(
'level' => PersonalizeLogLevel::INFO,
'message' => "The Decision Set {$title} was pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
DummyAcquiaLiftHttpClient::clearLoggedRequests();
$this->logger
->clearLogs();
$lift_api = $this
->getAcquiaLiftAPI(TRUE);
try {
$lift_api
->saveDecisionSet($name, $title, $options);
} catch (Exception $e) {
$this
->assertTrue($e instanceof AcquiaLiftException);
}
// Confirm the request URI and body are as expected.
$this
->assertAPIRequestURI($expected_uri, $logged_requests[0]['uri']);
$this
->assertEqual($expected_body, $logged_requests[0]['body']);
$logs = array(
array(
'level' => PersonalizeLogLevel::ERROR,
'message' => "The Decision Set {$title} could not be pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
DummyAcquiaLiftHttpClient::clearLoggedRequests();
$this->logger
->clearLogs();
}