forked from contributte/datagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
820395c
commit bdc1245
Showing
2 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
<?php | ||
|
||
namespace Ublaboo\DataGrid\Tests\Cases; | ||
|
||
use Tester\TestCase, | ||
Tester\Assert, | ||
Ublaboo, | ||
Nette, | ||
LeanMapper; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
require __DIR__ . '/../Files/XTestingDataGridFactory.php'; | ||
|
||
final class RowTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Ublaboo\DataGrid\DataGrid | ||
*/ | ||
private $grid; | ||
|
||
|
||
public function setUp() | ||
{ | ||
$factory = new Ublaboo\DataGrid\Tests\Files\XTestingDataGridFactory; | ||
$this->grid = $factory->createXTestingDataGrid(); | ||
} | ||
|
||
|
||
public function testArray() | ||
{ | ||
$item = ['id' => 20, 'name' => 'John Doe']; | ||
|
||
$row = new Ublaboo\DataGrid\Row($this->grid, $item, 'id'); | ||
|
||
Assert::same(20, $row->getId()); | ||
Assert::same('John Doe', $row->getValue('name')); | ||
} | ||
|
||
|
||
public function testObject() | ||
{ | ||
$item = (object) ['id' => 20, 'name' => 'John Doe']; | ||
|
||
$row = new Ublaboo\DataGrid\Row($this->grid, $item, 'id'); | ||
|
||
Assert::same(20, $row->getId()); | ||
} | ||
|
||
|
||
public function testLeanMapperEntity() | ||
{ | ||
$entity = new XTestingLMDataGridEntity(['id' => 20, 'name' => 'John Doe', 'age' => 23]); | ||
$entity2 = new XTestingLMDataGridEntity2(['id' => 21, 'name' => 'Francis', 'age' => 20]); | ||
|
||
$entity->setGirlfriend($entity2); | ||
|
||
$row = new Ublaboo\DataGrid\Row($this->grid, $entity, 'id'); | ||
|
||
Assert::same('John Doe', $row->getValue('name')); | ||
Assert::same(23, $row->getValue('age')); | ||
Assert::same(20, $row->getValue('girlfriend.age')); | ||
} | ||
|
||
|
||
public function testDoctrineEntity() | ||
{ | ||
$entity = new XTestingDDataGridEntity(['id' => 20, 'name' => 'John Doe', 'age' => 23]); | ||
$entity2 = new XTestingDDataGridEntity(['id' => 21, 'name' => 'Francis', 'age' => 20]); | ||
|
||
$entity->setPartner($entity2); | ||
|
||
$row = new Ublaboo\DataGrid\Row($this->grid, $entity, 'id'); | ||
|
||
Assert::same(20, $row->getId()); | ||
Assert::same('John Doe', $row->getValue('name')); | ||
Assert::same(23, $row->getValue('age')); | ||
Assert::same(20, $row->getValue('partner.age')); | ||
} | ||
|
||
} | ||
|
||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property XTestingLMDataGridEntity2|NULL $girlfriend | ||
*/ | ||
class XTestingLMDataGridEntity extends LeanMapper\Entity | ||
{ | ||
|
||
private $age; | ||
|
||
|
||
public function getAge() | ||
{ | ||
return $this->age; | ||
} | ||
|
||
|
||
public function setAge($age) | ||
{ | ||
$this->age = $age; | ||
} | ||
|
||
} | ||
|
||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
*/ | ||
class XTestingLMDataGridEntity2 extends LeanMapper\Entity | ||
{ | ||
|
||
private $age; | ||
|
||
|
||
public function getAge() | ||
{ | ||
return $this->age; | ||
} | ||
|
||
|
||
public function setAge($age) | ||
{ | ||
$this->age = $age; | ||
} | ||
|
||
} | ||
|
||
|
||
class XTestingDDataGridEntity extends Nette\Object | ||
{ | ||
|
||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* @var integer | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @ORM\Column(type="int") | ||
* @var int | ||
*/ | ||
private $age; | ||
|
||
private $partner; | ||
|
||
|
||
public function __construct($args) | ||
{ | ||
$this->id = $args['id']; | ||
$this->age = $args['age']; | ||
$this->name = $args['name']; | ||
} | ||
|
||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* @return integer | ||
*/ | ||
final public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
public function getAge() | ||
{ | ||
return $this->age; | ||
} | ||
|
||
|
||
public function setPartner($p) | ||
{ | ||
$this->partner = $p; | ||
} | ||
|
||
|
||
public function getPartner() | ||
{ | ||
return $this->partner; | ||
} | ||
|
||
} | ||
|
||
|
||
$test_case = new RowTest; | ||
$test_case->run(); |