1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Records\Tests\Traits\HasPrimaryKey; |
4
|
|
|
|
5
|
|
|
use Nip\Database\Connections\Connection; |
6
|
|
|
use Nip\Records\Record; |
7
|
|
|
use Nip\Records\RecordManager as Records; |
8
|
|
|
use Nip\Records\Tests\AbstractTest; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class RecordTest |
12
|
|
|
* @package Nip\Records\Tests\Traits\HasPrimaryKey |
13
|
|
|
*/ |
14
|
|
|
class RecordTraitTest extends AbstractTest |
15
|
|
|
{ |
16
|
|
|
public function testGetPrimaryKeySimple() |
17
|
|
|
{ |
18
|
|
|
$this->object->getManager()->setPrimaryKey('id'); |
|
|
|
|
19
|
|
|
$this->object->id = 99; |
20
|
|
|
|
21
|
|
|
static::assertEquals('99', $this->object->getPrimaryKey()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGetPrimaryKeyComposite() |
25
|
|
|
{ |
26
|
|
|
$this->object->getManager()->setPrimaryKey(['id_parent', 'type']); |
|
|
|
|
27
|
|
|
$this->object->id_parent = 99; |
|
|
|
|
28
|
|
|
$this->object->type = 'book'; |
|
|
|
|
29
|
|
|
|
30
|
|
|
static::assertEquals(['id_parent' => 99, 'type' => 'book'], $this->object->getPrimaryKey()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testHasPrimaryKeyComposite() |
34
|
|
|
{ |
35
|
|
|
$this->object->getManager()->setPrimaryKey(['id_parent', 'type']); |
|
|
|
|
36
|
|
|
static::assertFalse($this->object->hasPrimaryKey()); |
37
|
|
|
|
38
|
|
|
$this->object->id_parent = null; |
|
|
|
|
39
|
|
|
$this->object->type = ''; |
|
|
|
|
40
|
|
|
static::assertFalse($this->object->hasPrimaryKey()); |
41
|
|
|
|
42
|
|
|
$this->object->id_parent = 0; |
43
|
|
|
static::assertFalse($this->object->hasPrimaryKey()); |
44
|
|
|
|
45
|
|
|
$this->object->id_parent = 1; |
46
|
|
|
static::assertTrue($this->object->hasPrimaryKey()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function setUp() |
50
|
|
|
{ |
51
|
|
|
parent::setUp(); |
52
|
|
|
$wrapper = new Connection(false); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$manager = new Records(); |
55
|
|
|
$manager->setDB($wrapper); |
56
|
|
|
$manager->setTable('pages'); |
57
|
|
|
|
58
|
|
|
$this->object = new Record(); |
59
|
|
|
$this->object->setManager($manager); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|