456
456
# Clean up as we no longer need it, deleteWData will delete dataset even if it has data assigned to it
457
457
$dataSet -> deleteWData();
460
public function testAddRemoteDataSet()
462
$name = Random::generateString(8, 'phpunit');
464
$response = $this->client->post('/dataset', [
469
'uri' => 'http://localhost/resources/RemoteDataSet.json',
470
'dataRoot' => 'data',
474
# Check if call was successful
475
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
476
$object = json_decode($this->client->response->body());
477
$this->assertObjectHasAttribute('data', $object);
478
$this->assertObjectHasAttribute('id', $object);
480
# Check dataSet object
481
$this->assertSame($name, $object->data->dataSet);
482
$this->assertSame(1, $object->data->isRemote);
483
$this->assertSame('http://localhost/resources/RemoteDataSet.json', $object->data->uri);
484
$this->assertSame(1, $object->data->clearRate);
485
$this->assertSame(0, $object->data->refreshRate);
486
$this->assertSame(0, $object->data->lastClear);
489
public function testEditRemoteDataSet()
491
$name = Random::generateString(8, 'phpunit');
492
$name2 = Random::generateString(8, 'phpunit');
494
// add DataSet with wrapper
495
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create($name, '', 'remote', 1, 'GET', 'http://localhost/resources/RemoteDataSet.json', '', '', '', '', 1, 0, null, 'data');
498
$response = $this->client->put('/dataset/' . $dataSet->dataSetId, [
503
'uri' => 'http://localhost/resources/RemoteDataSet.json',
504
'dataRoot' => 'data',
507
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
509
# Check if call was successful
510
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
511
$object = json_decode($this->client->response->body());
512
$this->assertObjectHasAttribute('data', $object);
513
$this->assertObjectHasAttribute('id', $object);
515
# Check dataSet object
516
$this->assertSame($name2, $object->data->dataSet);
517
$this->assertSame(1, $object->data->isRemote);
518
$this->assertSame('http://localhost/resources/RemoteDataSet.json', $object->data->uri);
519
$this->assertSame(3600, $object->data->clearRate);
520
$this->assertSame(1, $object->data->refreshRate);
523
public function testRemoteDataSetData()
525
// copy json file to /web folder
526
shell_exec('cp -r ' . PROJECT_ROOT . '/tests/resources/RemoteDataSet.json ' . PROJECT_ROOT . '/web');
528
$name = Random::generateString(8, 'phpunit');
529
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create($name, '', 'remote', 1, 'GET', 'http://localhost/RemoteDataSet.json', '', '', '', '', 1, 0, null, 'data');
531
// call the remote dataSet test
532
$response = $this->client->post('/dataset/remote/test', [
533
'testDataSetId' => $dataSet->dataSetId,
538
'uri' => 'http://localhost/RemoteDataSet.json',
539
'dataRoot' => 'data',
544
# Check if call was successful
545
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
546
$object = json_decode($this->client->response->body());
547
$this->assertObjectHasAttribute('data', $object);
548
$this->assertObjectHasAttribute('id', $object);
549
$this->assertSame($object->id, $dataSet->dataSetId);
550
$this->assertNotEmpty($object->data->entries);
552
foreach ($object->data->entries as $entry) {
553
$this->assertSame('Title 1', $entry->data[0]->title);
554
$this->assertSame(2, $entry->data[1]->id);
555
$this->assertSame('2019-07-31 06:51:00', $entry->data[2]->Date);
558
// remove json file from /web folder
559
shell_exec('rm -r ' . PROJECT_ROOT . '/web/RemoteDataSet.json');