* Infolog - Fix project got lost on reload if set via link

This commit is contained in:
nathangray 2017-12-05 09:44:55 -07:00
parent fade7185ae
commit 9c397dd69c
2 changed files with 56 additions and 3 deletions

View File

@ -479,6 +479,8 @@ class infolog_bo
$info['info_link_id'] = 0; // link might have been deleted
$info['info_custom_from'] = (int)!!$info['info_from'];
$this->get_pm_id($info);
return False;
}
@ -1165,10 +1167,11 @@ class infolog_bo
}
Link::unlink($old_link_id);
}
// if added link is a project and no other project selected, also add as project
if ($app == 'projectmanager' && $id && !$values['pm_id'])
// if linked to a project and no other project selected, also add as project
$links = Link::get_links('infolog', $values['info_id'], 'projectmanager');
if (!$values['pm_id'] && count($links))
{
$values['old_pm_id'] = $values['pm_id'] = $id;
$values['old_pm_id'] = $values['pm_id'] = array_pop($links);
}
}

View File

@ -6,6 +6,7 @@ namespace EGroupware\Infolog;
require_once realpath(__DIR__.'/../../api/tests/AppTest.php'); // Application test base
use Egroupware\Api;
use Egroupware\Api\Link;
use Egroupware\Api\Etemplate;
/**
@ -150,6 +151,55 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
$this->checkElements();
}
/**
* Add a project by only adding it as a link. First linked project gets
* taken as _the_ project.
*/
public function testAddProjectViaLink()
{
// Saving the infolog should try to send a notification
$this->bo->tracking->expects($this->exactly(2))
->method('track')
->withConsecutive(
// First call - creation
[$this->callback(function($subject) { return is_null($subject['pm_status']);})],
// Second call - after setting project
[$this->callback(function($subject) { return $subject['pm_id'] == $this->pm_id;})]
);
$info = $this->getTestInfolog();
$this->info_id = $this->bo->write($info);
$this->assertInternalType('integer', $this->info_id);
$this->assertGreaterThan(0, $this->info_id);
// Force links to run notification now so we get valid testing - it
// usually waits until Egw::on_shutdown();
Api\Link::run_notifies();
// Now load it again
$info = $this->bo->read($this->info_id);
// Set project by link
Link::link('infolog', $this->info_id, 'projectmanager', $this->pm_id);
Api\Link::run_notifies();
$this->bo->write($info);
// Now load it again
$info = $this->bo->read($this->info_id);
// Check pm_id is there
$this->assertNotNull($info['pm_id'], 'Project was not set');
// Force links to run notification now so we get valid testing - it
// usually waits until Egw::on_shutdown();
Api\Link::run_notifies();
// Check project
$this->checkElements();
}
/**
* Create a new infolog entry, set project via info_contact
*/