コード例 #1
0
ファイル: TableTest.php プロジェクト: taviroquai/duality
 /**
  * Test table structure
  */
 public function testTable()
 {
     $table = new Table();
     $column = new Property('dummy');
     $table->addColumn($column);
     $row = new TableRow($table);
     $expected = 'value';
     $row->addData($column, $expected);
     $result = $row->getData($column);
     $this->assertEquals($expected, $result);
     $expected = array(array('dummy' => $expected));
     $table->addRow($row);
     $this->assertEquals($table->toArray(), $expected);
     $expected = array('dummy' => $column);
     $result = $table->getColumns();
     $this->assertEquals($expected, $result);
     $expected = TRUE;
     $result = $table->columnExists($column);
     $this->assertEquals($expected, $result);
     $expected = array(array('dummy' => 'value'));
     $table->reset();
     $column = new Property('dummy');
     $table->addColumn($column);
     $table->importArray($expected);
     $result = $table->toArray();
     $this->assertEquals($expected, $result);
     $expected = "dummy\nvalue\n";
     $result = $table->toCSV();
     $this->assertEquals($expected, $result);
     $expected = array(array());
     $table->removeColumn('dummy');
     $result = $table->toArray();
     $this->assertEquals($expected, $result);
 }
コード例 #2
0
ファイル: Table.php プロジェクト: taviroquai/duality
 /**
  * Loads items into storage
  * 
  * @param array $data The data to be loaded
  * 
  * @return void
  */
 public function importArray($data)
 {
     foreach ($data as $key => $item) {
         $row = new TableRow($this);
         foreach ($this->getColumns() as $col => $prop) {
             if (isset($item[$col])) {
                 $property = $this->columns->get($col);
                 $row->addData($property, $item[$col]);
             }
             $this->insertRow($row, $key);
         }
     }
 }