]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Documents/Bug61144Test.php
Release 6.5.12
[Github/sugarcrm.git] / tests / modules / Documents / Bug61144Test.php
1 <?php
2 /*********************************************************************************
3  * By installing or using this file, you are confirming on behalf of the entity
4  * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5  * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6  * http://www.sugarcrm.com/master-subscription-agreement
7  *
8  * If Company is not bound by the MSA, then by installing or using this file
9  * you are agreeing unconditionally that Company will be bound by the MSA and
10  * certifying that you have authority to bind Company accordingly.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15 /**
16  * Bug #61144: remove doc link in field: Related Document, if linked doc is got deleted from the system
17  *
18  * @ticket 61144
19  */
20
21 require_once('modules/Documents/Document.php');
22
23 class Bug61144Test extends Sugar_PHPUnit_Framework_TestCase
24 {
25     protected $parent_doc;
26     protected $relate_doc;
27
28     /**
29      * @var DocumentRevision
30      */
31     protected $revision;
32
33     public function setUp()
34     {
35         SugarTestHelper::setUp('beanFiles');
36         SugarTestHelper::setUp('beanList');
37         SugarTestHelper::setUp('current_user');
38
39         $this->relate_doc = new Document();
40         $this->relate_doc->document_name = 'Relate doc';
41         $this->relate_doc->save();
42
43         $this->parent_doc = new Document();
44         $this->parent_doc->document_name = 'Parent doc';
45         $this->parent_doc->related_doc_id = $this->relate_doc->id;
46         $this->parent_doc->save();
47
48         $this->revision = new DocumentRevision();
49         $this->revision->revision = 1;
50         $this->revision->doc_id = $this->relate_doc->id;
51         $this->revision->save();
52     }
53
54     public function tearDown()
55     {
56         SugarTestHelper::tearDown();
57         $GLOBALS['db']->query("DELETE FROM documents WHERE id in ('{$this->relate_doc->id}', '{$this->parent_doc->id}')");
58         $GLOBALS['db']->query("DELETE FROM {$this->revision->table_name} WHERE id in ('{$this->revision->id}')");
59     }
60
61     /**
62      * @group 61144
63      */
64     public function testDeleteRelateDocument()
65     {
66         $this->relate_doc->mark_deleted($this->relate_doc->id);
67         $this->parent_doc->fill_in_additional_detail_fields();
68         $this->assertEmpty($this->parent_doc->related_doc_name);
69     }
70
71     /**
72      * @group 61144
73      */
74     public function testRealteDocumentExist()
75     {
76         $this->parent_doc->fill_in_additional_detail_fields();
77         $this->assertEquals('Relate doc', $this->parent_doc->related_doc_name);
78     }
79
80     /**
81      * @group 61144
82      */
83     public function testDeleteRelateDocumentRevision()
84     {
85         $this->revision->mark_deleted($this->revision->id);
86         $actual = $this->revision->get_document_revision_name($this->revision->id);
87         $this->assertEmpty($actual, 'Deleted data is returned');
88     }
89
90     /**
91      * @group 61144
92      */
93     public function testRealteDocumentRevision()
94     {
95         $actual = $this->revision->get_document_revision_name($this->revision->id);
96         $this->assertEquals($this->revision->revision, $actual, 'Revision is incorrect');
97     }
98 }