From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Test/SyncTest.php | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 library/Director/Test/SyncTest.php (limited to 'library/Director/Test/SyncTest.php') diff --git a/library/Director/Test/SyncTest.php b/library/Director/Test/SyncTest.php new file mode 100644 index 0000000..7614ff9 --- /dev/null +++ b/library/Director/Test/SyncTest.php @@ -0,0 +1,105 @@ +source = ImportSource::create(array( + 'source_name' => 'testimport', + 'provider_class' => 'Icinga\\Module\\Director\\Test\\ImportSourceDummy', + 'key_column' => $this->keyColumn, + )); + $this->source->store($this->getDb()); + + $this->rule = SyncRule::create(array( + 'rule_name' => 'testrule', + 'object_type' => $this->objectType, + 'update_policy' => 'merge', + 'purge_existing' => 'n' + )); + $this->rule->store($this->getDb()); + + $this->sync = new Sync($this->rule); + } + + public function tearDown() + { + // properties should be deleted automatically + if ($this->rule !== null && $this->rule->hasBeenLoadedFromDb()) { + $this->rule->delete(); + } + + if ($this->source !== null && $this->source->hasBeenLoadedFromDb()) { + $this->source->delete(); + } + + // find objects created by this class and delete them + $db = $this->getDb(); + $dummy = IcingaObject::createByType($this->objectType, array(), $db); + $query = $db->getDbAdapter()->select() + ->from($dummy->getTableName()) + ->where('object_name LIKE ?', 'SYNCTEST_%'); + + /** @var IcingaObject $object */ + foreach (IcingaObject::loadAllByType($this->objectType, $db, $query) as $object) { + $object->delete(); + } + + // make sure cache is clean for other tests + PrefetchCache::forget(); + DbObject::clearAllPrefetchCaches(); + } + + /** + * @param array $rows + * + * @throws IcingaException + */ + protected function runImport($rows) + { + ImportSourceDummy::setRows($rows); + $this->source->runImport(); + if ($this->source->get('import_state') !== 'in-sync') { + throw new IcingaException('Import failed: %s', $this->source->get('last_error_message')); + } + } + + protected function setUpProperty($properties = array()) + { + $properties = array_merge(array( + 'rule_id' => $this->rule->id, + 'source_id' => $this->source->id, + 'merge_policy' => 'override', + ), $properties); + + $this->properties[] = $property = SyncProperty::create($properties); + $property->store($this->getDb()); + } +} -- cgit v1.2.3