From 590b23b2a86e6aaa7fb3efdba67cc37fca1220c9 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 6 Nov 2017 15:16:08 -0700 Subject: [PATCH] * Infolog - Fix parent contact going missing when creating a sub entry --- infolog/inc/class.infolog_bo.inc.php | 7 ++- infolog/templates/default/index.xet | 2 +- infolog/tests/ContactTest.php | 73 ++++++++++++++++++++++++- infolog/tests/SetProjectManagerTest.php | 5 +- 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index 799889281f..c7520f67c0 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -1054,7 +1054,7 @@ class infolog_bo // Update modified timestamp of parent if($values['info_id_parent'] && $touch_modified) { - $parent = $this->read($values['info_id_parent'], false, 'server', true); + $parent = $this->read($values['info_id_parent'], true, 'server', true); $this->write($parent, false, true, false, true, false, null, $ignore_acl); } } @@ -1072,6 +1072,8 @@ class infolog_bo protected function write_check_links(&$values) { $old_link_id = (int)$values['info_link_id']; + $from = $values['info_from']; + if($values['info_contact'] && !( is_array($values['info_contact']) && $values['info_contact']['id'] == 'none' ) || ( @@ -1132,7 +1134,8 @@ class infolog_bo else { unset($values['info_link_id']); - $values['info_from'] = null; + unset($values['info_contact']); + $values['info_from'] = $from ? $from : null; } if($values['info_id'] && $values['old_pm_id'] !== $values['pm_id']) { diff --git a/infolog/templates/default/index.xet b/infolog/templates/default/index.xet index c64a7a1ba1..4f46cf2a1d 100644 --- a/infolog/templates/default/index.xet +++ b/infolog/templates/default/index.xet @@ -207,7 +207,7 @@ - + diff --git a/infolog/tests/ContactTest.php b/infolog/tests/ContactTest.php index 4798b8a83d..e5e7526074 100644 --- a/infolog/tests/ContactTest.php +++ b/infolog/tests/ContactTest.php @@ -42,9 +42,11 @@ class ContactTest extends \EGroupware\Api\AppTest public function tearDown() { // Double delete to make sure it's gone, not preserved due to history setting - $this->bo->delete($this->info_id); - $this->bo->delete($this->info_id); - + if($this->info_id) + { + $this->bo->delete($this->info_id); + $this->bo->delete($this->info_id); + } $this->bo = null; } @@ -153,6 +155,71 @@ class ContactTest extends \EGroupware\Api\AppTest // Make a call to edit, looks like initial load $_REQUEST['info_id'] = $this->info_id; $this->ui->edit(); + unset($_REQUEST['info_id']); + } + + /** + * Test that creating a sub-infolog keeps info_contact on the parent + * + * @ticket 24920 + */ + public function testSubEntry() + { + // Parent needs a project & contact for this + $content = array( + 'contact' => array( + 'app' => 'addressbook', + 'id' => Null, + 'search'=> 'Free text' + ) + ); + $parent = $this->getTestInfolog($content); + + // Skipping notifications - save initial state + $parent_id = $this->bo->write($parent, true, true, true, true); + + // Mock the etemplate call to check sub gets parent's contact + $sub = array(); + $this->ui->tmpl->expects($this->once()) + ->method('exec') + ->will( + $this->returnCallback(function($method, $info) use($parent, &$sub) { + $this->assertNull($info['info_id']); + $this->assertEquals($parent['info_id'], $info['info_id_parent']); + $this->assertEquals($parent['info_contact']['id'], $info['info_contact']['id']); + $this->assertEquals($parent['info_contact']['app'], $info['info_contact']['app']); + $this->assertEquals($parent['info_from'], $info['info_from']); + $sub = $info; + return true; + }) + ); + + // Make a sub-entry + $_REQUEST['action'] = 'sp'; + $_REQUEST['action_id'] = $parent['info_id']; + $this->ui->edit(); + + // Skipping notifications - save initial state + $this->info_id = $this->bo->write($sub, true, true, true, true); + + // Read it back to check + $saved = $this->bo->read($this->info_id); + + $this->assertEquals($parent['pm_id'], $saved['pm_id']); + $this->assertEquals($parent['info_from'], $saved['info_from']); + $this->assertEquals(json_encode($parent['info_contact']), json_encode($saved['info_contact'])); + $this->assertEquals($parent_id, $saved['info_id_parent']); + + // Check parent + $parent_reload = $this->bo->read($parent_id); + + $this->assertEquals($parent['pm_id'], $parent_reload['pm_id']); + $this->assertEquals($parent['info_from'], $parent_reload['info_from']); + $this->assertEquals($parent['info_contact'], $parent_reload['info_contact']); + + // Remove parent (twice, for history preservation) + $this->bo->delete($parent_id); + $this->bo->delete($parent_id); } /** diff --git a/infolog/tests/SetProjectManagerTest.php b/infolog/tests/SetProjectManagerTest.php index 28472d7a81..06320c46b5 100644 --- a/infolog/tests/SetProjectManagerTest.php +++ b/infolog/tests/SetProjectManagerTest.php @@ -481,7 +481,10 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest $info = $this->bo->read($this->info_id); // Check contact was cleared - $this->assertNull($info['info_contact'], 'Contact was not cleared'); + $this->assertTrue(is_null($info['info_contact']) || ( + $info['info_contact']['id'] == 'none' && !$info['info_contact']['search']), + 'Contact was not cleared' + ); // Check pm_id is gone $this->assertNull($info['pm_id'], 'Project was not removed');