*/ class UpdaterDeliveryTest extends TestCase { /** * @var MonitoringStorage */ protected $deliveryMonitoringService; /** * @var DeliveryUpdaterTask */ protected $deliveryUpdaterTask; protected $persistence; protected $pmMock; /** @var string */ protected $deliveryExecutionId = 'http://sample/first.rdf#i1450191587554175_test_record'; /** * Test the UpdateDelivery task for updating labels */ public function testUpdateDeliveryLabels() { $this->loadFixture(); $update = $this->getDeliveryUpdaterTask()->updateDeliveryLabels('http://sample/first.rdf#i1450191587554180_test_record', 'Delivery test 2'); $this->assertTrue($update); $result = $this->getDeliveryMonitoringService()->find([ [MonitoringStorage::DELIVERY_ID => 'http://sample/first.rdf#i1450191587554180_test_record'], ]); $this->assertEquals(count($result), 1); $this->assertEquals($result[0]->get()[MonitoringStorage::DELIVERY_NAME], 'Delivery test 2', 1); } /** * Load fixtures for delivery monitoring table * @return array */ protected function loadFixture() { $data = [ [ MonitoringStorage::COLUMN_DELIVERY_EXECUTION_ID => 'http://sample/first.rdf#i1450191587554175_test_record', MonitoringStorage::COLUMN_TEST_TAKER => 'test_taker_1', MonitoringStorage::COLUMN_STATUS => 'active_test', OntologyDeliveryExecution::PROPERTY_SUBJECT => 'http://sample/first.rdf#i1450191587554175_test_user', MonitoringStorage::DELIVERY_NAME => 'Delivery test 1', MonitoringStorage::DELIVERY_ID => 'http://sample/first.rdf#i1450191587554180_test_record', ] ]; foreach ($data as $item) { $dataModel = $this->getDeliveryMonitoringService()->getData($this->getDeliveryExecution($item[MonitoringStorage::DELIVERY_EXECUTION_ID])); foreach ($item as $key => $val) { $dataModel->addValue($key, $val); } $this->getDeliveryMonitoringService()->save($dataModel); } return [ [$data], ]; } /** * @param null $id * @return object */ protected function getDeliveryExecution($id = null) { if ($id === null) { $id = $this->deliveryExecutionId; } $prophet = new \Prophecy\Prophet(); $deliveryExecutionProphecy = $prophet->prophesize(DeliveryExecution::class); $deliveryExecutionProphecy->getIdentifier()->willReturn($id); $stateProphecy = $this->prophesize(\core_kernel_classes_Resource::class); $stateProphecy->getUri()->willReturn(DeliveryExecution::STATE_PAUSED); $deliveryExecutionProphecy->getState()->willReturn($stateProphecy); return $deliveryExecutionProphecy->reveal(); } /** * Init Persistence with mock. */ protected function initPersistence() { $this->pmMock = $this->getSqlMock('test_monitoring'); $this->persistence = $this->pmMock->getPersistenceById('test_monitoring'); DbSetup::generateTable($this->persistence); } /** * Init DeliveryMonitoring Service */ protected function initDeliveryMonitoringService() { $this->deliveryMonitoringService = new MonitoringStorage([ MonitoringStorage::OPTION_PERSISTENCE => 'test_monitoring', MonitoringStorage::OPTION_PRIMARY_COLUMNS => array( 'delivery_execution_id', 'status', 'current_assessment_item', 'test_taker', 'authorized_by', 'start_time', 'end_time', 'delivery_name', 'delivery_id' ) ]); $this->initPersistence(); $config = $this->prophesize(\common_persistence_KeyValuePersistence::class); $config->get(\common_persistence_Manager::SERVICE_ID)->willReturn($this->pmMock); $config->get(DeliveryMonitoringService::SERVICE_ID)->willReturn($this->deliveryMonitoringService); $this->deliveryMonitoringService->setServiceLocator(new ServiceManager($config->reveal())); } /** * Init DeliveryUpdater task object */ protected function initDeliveryUpdaterTask() { $this->deliveryUpdaterTask = new DeliveryUpdaterTask(); $this->deliveryUpdaterTask->setServiceLocator($this->getDeliveryMonitoringService()->getServiceLocator()); } /** * Get DeliveryMonitoringService object * * @return MonitoringStorage */ protected function getDeliveryMonitoringService() { if (!$this->deliveryMonitoringService) { $this->initDeliveryMonitoringService(); } return $this->deliveryMonitoringService; } /** * Get DeliveryUpdaterTask object * * @return DeliveryUpdaterTask */ protected function getDeliveryUpdaterTask() { if (!$this->deliveryUpdaterTask) { $this->initDeliveryUpdaterTask(); } return $this->deliveryUpdaterTask; } }