Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_getSearchMethods.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\Pu
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp_commonfamily.php';
10 
12 {
13  /**
14  * import TST_UPDTATTR
15  * @static
16  * @return array|string
17  */
18  protected static function getCommonImportFile()
19  {
20  return array(
21  "PU_data_dcp_getSearchMethods.ods"
22  );
23  }
24  /**
25  * Test getSearchMethods() method
26  *
27  * @dataProvider data_getSearchMethods
28  * @param $famid
29  * @param $attrid
30  * @param $type
31  * @param $hasMethods
32  * @internal param $data
33  */
34  public function test_getSearchMethods($famid, $attrid, $type, $hasMethods)
35  {
37  $this->assertTrue(is_object($tmpDoc) , sprintf("Error creating temorary document from family '%s'.", $famid));
38 
39  $methodList = $tmpDoc->getSearchMethods($attrid, $type);
40  $this->assertTrue((count($methodList) > 0) , sprintf("Empty method list for attribute '%s' with type '%s' from family '%s'.", $attrid, $type, $famid));
41 
42  $methodNameList = array_map(function ($elmt)
43  {
44  return $elmt['method'];
45  }
46  , $methodList);
47 
48  foreach ($hasMethods as $methodName) {
49  $this->assertTrue(in_array($methodName, $methodNameList) , sprintf("Expected method '%s' not found in returned methods (%s)", $methodName, join(', ', $methodNameList)));
50  }
51  }
52  public function data_getSearchMethods()
53  {
54  return array(
55  array(
56  'TST_GETSEARCHMETHODS',
57  's_date',
58  'date',
59  array(
60  '::getDate(-1)',
61  '::getDate()',
62  '::getDate(1)'
63  )
64  ) ,
65  array(
66  'TST_GETSEARCHMETHODS',
67  's_timestamp',
68  'timestamp',
69  array(
70  '::getDate(-1)',
71  '::getDate()',
72  '::getDate(1)'
73  )
74  ) ,
75  array(
76  'TST_GETSEARCHMETHODS_OVERRIDE',
77  's_date',
78  'date',
79  array(
80  '::getDate(-365)',
81  '::getDate(-1)',
82  '::getDate()',
83  '::getDate(1)',
84  '::getDate(365)'
85  )
86  ) ,
87  array(
88  'TST_GETSEARCHMETHODS_OVERRIDE',
89  's_text',
90  'text',
91  array(
92  '::getFoo()'
93  )
94  ) ,
95  array(
96  'TST_GETSEARCHMETHODS_OVERRIDE',
97  's_double',
98  'double("%.02f")',
99  array(
100  '::getTwoCents()'
101  )
102  )
103  );
104  }
105  /**
106  * Test invalid/non explicitly declared search methods
107  *
108  * @dataProvider data_invalidSearchMethod
109  * @param string $dSearchId
110  */
111  public function test_invalidSearchMethod($dSearchId)
112  {
113  /**
114  * @var \_DSEARCH $dSearch
115  */
116  $dSearch = new_Doc(self::$dbaccess, $dSearchId, true);
117  $this->assertTrue($dSearch->isAlive() , sprintf("dSearch with id '%s' is not alive.", $dSearchId));
118  $sql = $dSearch->getSqlDetailFilter();
119  $this->assertTrue(($sql == 'false') , sprintf("getSqlDetailFilter() did not returned (string)'false' (returned value is '%s').", $sql));
120  }
121  public function data_invalidSearchMethod()
122  {
123  return array(
124  array(
125  'DSEARCH_TST_GETSEARCHMETHODS_1'
126  ) ,
127  array(
128  'DSEARCH_TST_GETSEARCHMETHODS_2'
129  )
130  );
131  }
132 }
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
test_getSearchMethods($famid, $attrid, $type, $hasMethods)
← centre documentaire © anakeen