You are here

public function AcquiaLiftTest::testSaveFixedTargetingMapping in Acquia Lift Connector 7

Test AcquiaLiftAPI->saveFixedTargetingMapping()

File

tests/AcquiaLiftAPI.test, line 1173
Unit tests for Acquia Lift module.

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

public function testSaveFixedTargetingMapping() {
  $lift_api = $this
    ->getAcquiaLiftAPI();
  $agentName = 'some-agent-name';
  $pointName = 'some-point-name';
  $map = array(
    'key' => 'data',
  );
  $lift_api
    ->saveFixedTargetingMapping($agentName, $pointName, $map);

  // Define the requests we expect to have been made to our dummy http
  // client for this operation.
  $requests = array(
    array(
      'type' => 'put',
      'uri' => "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/agent-api/{$agentName}/points/{$pointName}/fixed-targeting?apikey={$lift_api->getAdminKey()}",
      'headers' => array(
        'Content-Type' => 'application/json; charset=utf-8',
        'Accept' => 'application/json',
      ),
      'options' => array(),
      'body' => $map,
    ),
  );

  // Confirm the expected requests were made.
  $this
    ->assertAPIRequests($requests);
  $logs = array(
    array(
      'level' => PersonalizeLogLevel::INFO,
      'message' => "The fixed targeting mapping for point {$pointName} was successfully saved for campaign {$agentName}",
    ),
  );
  $this
    ->assertLogs($logs);
  $lift_api = $this
    ->getAcquiaLiftAPI(TRUE);
  try {
    $lift_api
      ->saveFixedTargetingMapping($agentName, $pointName, $map);
  } catch (Exception $e) {
    $this
      ->assertTrue($e instanceof AcquiaLiftException);
  }

  // Confirm the expected requests were made.
  $this
    ->assertAPIRequests($requests);
  $logs = array(
    array(
      'level' => PersonalizeLogLevel::ERROR,
      'message' => "The fixed targeting mapping for point {$pointName} could not be saved for campaign {$agentName}",
    ),
  );
  $this
    ->assertLogs($logs);
}