Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_getSortAttributes.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\PuTEST
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp_commonfamily.php';
10 
12 {
13  protected static function getCommonImportFile()
14  {
15  return array(
16  "PU_data_dcp_getSortAttributes.ods"
17  );
18  }
19  /**
20  * @dataProvider data_getSortAttributes
21  * @param $data
22  */
23  public function test_getSortAttributes($data)
24  {
25  if (!is_numeric($data['famid'])) {
26  $data['famid'] = getIdFromName(self::$dbaccess, $data['famid']);
27  }
28 
29  $famdoc = new \DocFam(self::$dbaccess, $data['famid']);
30  $attributes = $famdoc->getSortAttributes();
31  $count = count($attributes);
32  $this->assertTrue(($count == $data['expected']['count']) , sprintf("Got %d attributes while expecting %s: %s", $count, $data['expected']['count'], print_r(array_map(function ($e)
33  {
34  return $e->id;
35  }
36  , $attributes) , true)));
37 
38  foreach ($data['expected']['check'] as $check) {
39  $found = false;
40  foreach ($attributes as $attr) {
41  if ($attr->id == $check['id']) {
42  $found = true;
43  break;
44  }
45  }
46  $this->assertTrue($found, sprintf("Expected attribute '%s' not found.", $check['id']));
47  $this->assertTrue(($attr->getOption('sortable') == $check['sortable']) , sprintf("Attribute '%s' has sortable '%s' while expecting '%s'.", $attr->id, $attr->getOption('sortable') , $check['sortable']));
48  }
49  }
50  /**
51  * @return array
52  */
53  public function data_getSortAttributes()
54  {
55  return array(
56  array(
57  array(
58  'famid' => 'TST_GETSORTATTRIBUTES',
59  'expected' => array(
60  'count' => 2,
61  'check' => array(
62  array(
63  'id' => 's_text',
64  'sortable' => 'asc'
65  ) ,
66  array(
67  'id' => 's_date',
68  'sortable' => 'desc'
69  )
70  )
71  )
72  )
73  )
74  );
75  }
76 }
$dbaccess
Definition: checkVault.php:17
getIdFromName($dbaccess, $name)
$data
← centre documentaire © anakeen