You are here

public function PMPAPIPullWebTestCase::testPmpAPIValidThenExpired in Public Media Platform API Integration 7

Checks that node is unpublished when it becomes expired.

File

pmpapi_pull/tests/pmpapi_pull.test, line 220

Class

PMPAPIPullWebTestCase
Tests the functionality of the PMPAPI pull module.

Code

public function testPmpAPIValidThenExpired() {
  variable_set('pmpapi_pull_last_validity_check', time() - 100);
  $this
    ->createContentType();

  // Send up a doc (but don't create a node)
  $valid = new stdClass();
  $now = time();
  $valid->from = pmpapi_convert_timestamp(strtotime('-1 day', $now), $now);
  $valid->to = pmpapi_convert_timestamp(strtotime('+30 seconds', $now), $now);
  $values = array(
    'profile' => 'story',
    'attributes' => array(
      'valid' => $valid,
      'title' => $this
        ->randomName(20),
    ),
  );
  $doc = pmpapi_send($values);
  $this
    ->assertTrue(is_object($doc), 'Successfully pushed a doc to the PMP.');
  sleep(self::SLEEP_TIME);

  // Pull that (valid) doc
  $guid = $doc->attributes->guid;
  pmpapi_pull_pull_doc($guid);
  $node = node_load(1);
  $this
    ->assertTrue(is_object($node), 'Pulled doc and created node.');
  $this
    ->assertTrue($node->status, 'Valid node is published.');

  // Wait until doc is expired, and run check function
  sleep(45);
  pmpapi_pull_check_valid_dates();
  $valid_node = node_load(1, NULL, TRUE);
  $this
    ->assertFalse($valid_node->status, 'Now-expired node is unpublished.');
  pmpapi_remove($doc->attributes->guid);
}