forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountAllModelTest.php
More file actions
110 lines (91 loc) · 4.36 KB
/
Copy pathCountAllModelTest.php
File metadata and controls
110 lines (91 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Models;
use Tests\Support\Models\UserModel;
/**
* @group DatabaseLive
*
* @internal
*/
final class CountAllModelTest extends LiveModelTestCase
{
/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1617
*/
public function testCountAllResultsRespectsSoftDeletes(): void
{
$this->createModel(UserModel::class);
// testSeeder has 4 users....
$this->assertSame(4, $this->model->countAllResults());
$this->model->where('name', 'Derek Jones')->delete();
$this->assertSame(3, $this->model->countAllResults());
}
public function testcountAllResultsRecoverTempUseSoftDeletes(): void
{
$this->createModel(UserModel::class);
$this->model->delete(1);
$this->assertSame(4, $this->model->withDeleted()->countAllResults());
$this->assertSame(3, $this->model->countAllResults());
}
public function testcountAllResultsFalseWithDeletedTrue(): void
{
$builder = $this->loadBuilder('user');
$expectedSQL = $builder->testMode()->countAllResults();
$this->createModel(UserModel::class);
$this->model->delete(1);
$this->assertSame(4, $this->model->withDeleted()->countAllResults(false));
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
$this->assertSame(4, $this->model->countAllResults());
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertTrue($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
}
public function testcountAllResultsFalseWithDeletedFalse(): void
{
$builder = $this->loadBuilder('user');
$expectedSQL = $builder->testMode()->where('user.deleted_at', null)->countAllResults();
$this->createModel(UserModel::class);
$this->model->delete(1);
$this->assertSame(3, $this->model->withDeleted(false)->countAllResults(false));
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
$this->assertSame(3, $this->model->countAllResults());
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertTrue($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
}
public function testcountAllResultsFalseWithDeletedTrueUseSoftDeletesFalse(): void
{
$builder = $this->loadBuilder('user');
$expectedSQL = $builder->testMode()->countAllResults();
$this->createModel(UserModel::class);
$this->model->delete(1);
$this->setPrivateProperty($this->model, 'useSoftDeletes', false);
$this->assertSame(4, $this->model->withDeleted()->countAllResults(false));
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
$this->assertSame(4, $this->model->countAllResults());
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
}
public function testcountAllResultsFalseWithDeletedFalseUseSoftDeletesFalse(): void
{
$builder = $this->loadBuilder('user');
$expectedSQL = $builder->testMode()->where('user.deleted_at', null)->countAllResults();
$this->createModel(UserModel::class);
$this->model->delete(1);
$this->setPrivateProperty($this->model, 'useSoftDeletes', false);
$this->assertSame(3, $this->model->withDeleted(false)->countAllResults(false));
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
$this->assertSame(3, $this->model->countAllResults());
$this->assertSame($expectedSQL, (string) $this->db->getLastQuery());
$this->assertFalse($this->getPrivateProperty($this->model, 'tempUseSoftDeletes'));
}
}