]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/install/QuotesSeedDataTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / install / QuotesSeedDataTest.php
1 <?php
2 class QuotesSeedDataTest extends Sugar_PHPUnit_Framework_TestCase
3 {
4
5         var $quote_name;
6         
7         public function setUp()
8         {
9                 global $sugar_demodata;
10                 $sugar_demodata['company_name_array'] = array();
11                 $query = 'SELECT * FROM ACCOUNTS';
12                 $results = $GLOBALS['db']->limitQuery($query,0,10,true,"Error retrieving Accounts");
13         while($row = $GLOBALS['db']->fetchByAssoc($results)) {
14                 $sugar_demodata['company_name_array'][] = $row['name'];
15         }
16         
17         $this->quote_name = 'Test Quote ' . mktime();
18         
19                 $sugar_demodata['quotes_seed_data']['quotes'][0] = array(
20                         'name' => $this->quote_name,
21                         'quote_stage' => 'Draft',
22                         'date_quote_expected_closed' => '04/30/2012',
23                     'description' => 'This is a test that should contain one product group with two products and a total of three items',
24                          
25                 
26                     'bundle_data' => array(
27                                 0 => array (
28                                     'bundle_name' => 'Group 1',
29                                     'bundle_stage' => 'Draft',
30                                     'comment' => 'Three Computers',
31                                     'products' => array (
32                                                 1 => array('name'=>'TK 1000 Desktop', 'quantity'=>'1'),
33                                                 2 => array('name'=>'TK m30 Desktop', 'quantity'=>'2'),
34                                         ),
35                                 ),
36                         ),
37                 );
38         }
39
40         public function tearDown() {
41                 $sql = "SELECT * FROM quotes WHERE name = '{$this->quote_name}'";
42                 $results = $GLOBALS['db']->query($sql);
43                 $quote_id = '';
44                 
45         while($row = $GLOBALS['db']->fetchByAssoc($results)) {
46                   $quote_id = $row['id'];
47         }               
48         
49         $sql = "DELETE FROM quotes WHERE id = '{$quote_id}'";
50         $GLOBALS['db']->query($sql);
51
52         $sql = "DELETE FROM products WHERE quote_id = '{$quote_id}'";
53         $GLOBALS['db']->query($sql);           
54         
55         $bundle_id = '';
56         $sql = "SELECT bundle_id FROM product_bundle_quote WHERE quote_id = '{$quote_id}";
57
58         $results = $GLOBALS['db']->query($sql);
59         while($row = $GLOBALS['db']->fetchByAssoc($results)) {
60                   $bundle_id = $row['bundle_id'];
61                   
62                   $sql = "DELETE FROM product_bundle_product WHERE bundle_id = '{$bundle_id}'";
63                   $GLOBALS['db']->query($sql);
64                   
65                   $sql = "DELETE FROM product_bundle_quote WHERE bundle_id = '{$bundle_id}'";
66                   $GLOBALS['db']->query($sql);
67         }               
68         
69         if(!empty($bundle_id)) {
70                 $sql = "SELECT note_id FROM product_bundle_note WHERE bundle_id = '{$bundle_id}";
71                 $results = $GLOBALS['db']->query($sql);
72                 while($row = $GLOBALS['db']->fetchByAssoc($results)) {  
73                         $note_id = $row['note_id'];
74                         
75                         $sql = "DELETE FROM product_bundle_notes WHERE id = '{$note_id}'";
76                     $GLOBALS['db']->query($sql);
77                 }       
78                 
79                 $sql = "DELETE FROM product_bundle_note WHERE bundle_id = '{$bundle_id}'";
80                 $GLOBALS['db']->query($sql);
81         }
82         
83         }
84         
85         public function test_create_seed_quotes() {
86         require_once('install/seed_data/quotes_SeedData.php');
87                 $sql = "SELECT * FROM quotes WHERE name = '{$this->quote_name}'";
88                 $results = $GLOBALS['db']->query($sql); 
89                 $quote_created = false;   
90         while($row = $GLOBALS['db']->fetchByAssoc($results)) {
91                   $quote_created = true;
92         }       
93         
94         $this->assertTrue($quote_created);
95         }
96 }
97 ?>