Skip to content

Commit 6c0d6b8

Browse files
authored
[Core] - Show hidden properties (#99)
Allows returning hidden properties. Previously properties that were defined in the Entities $_hidden array were excluded from Model. These properties are now returned with ModelProperty::isHidden = true.
1 parent 67530bb commit 6c0d6b8

14 files changed

Lines changed: 176 additions & 213 deletions

File tree

plugins/bake/tests/Fixture/ActorsFixture.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,8 @@
88
/**
99
* ActorsFixture
1010
*/
11-
class ActorsFixture extends TestFixture
11+
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
1212
{
13-
/**
14-
* Fields
15-
*
16-
* @var array
17-
*/
18-
// phpcs:disable
19-
public $fields = [
20-
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
21-
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
22-
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
23-
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
24-
'_indexes' => [
25-
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
26-
],
27-
'_constraints' => [
28-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
29-
],
30-
'_options' => [
31-
'engine' => 'InnoDB',
32-
'collation' => 'latin1_swedish_ci'
33-
],
34-
];
35-
// phpcs:enable
3613
/**
3714
* Init method
3815
*

plugins/collection-view/tests/Fixture/ActorsFixture.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,8 @@
88
/**
99
* ActorsFixture
1010
*/
11-
class ActorsFixture extends TestFixture
11+
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
1212
{
13-
/**
14-
* Fields
15-
*
16-
* @var array
17-
*/
18-
// phpcs:disable
19-
public $fields = [
20-
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
21-
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
22-
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
23-
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
24-
'_indexes' => [
25-
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
26-
],
27-
'_constraints' => [
28-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
29-
],
30-
'_options' => [
31-
'engine' => 'InnoDB',
32-
'collation' => 'latin1_swedish_ci'
33-
],
34-
];
35-
// phpcs:enable
3613
/**
3714
* Init method
3815
*

plugins/core/src/Model/Model.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,9 @@ public function getProperty(string $columnName): ModelProperty
5050
*/
5151
private function assignProperties(): void
5252
{
53-
$hiddenAttributes = $this->entity->getHidden();
54-
55-
$columns = array_filter($this->schema->columns(), function ($column) use ($hiddenAttributes) {
56-
return !in_array($column, $hiddenAttributes) ? true : null;
57-
});
58-
59-
foreach ($columns as $columnName) {
53+
foreach ($this->schema->columns() as $columnName) {
6054
$modelProperty = (new ModelPropertyFactory($this->schema, $this->table, $columnName, $this->entity))
6155
->create();
62-
6356
$this->properties[$columnName] = $modelProperty;
6457
}
6558
}

plugins/core/tests/Fixture/ActorsFixture.php

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,11 @@
33

44
namespace MixerApi\Core\Test\Fixture;
55

6-
use Cake\TestSuite\Fixture\TestFixture;
7-
86
/**
97
* ActorsFixture
108
*/
11-
class ActorsFixture extends TestFixture
9+
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
1210
{
13-
/**
14-
* Fields
15-
*
16-
* @var array
17-
*/
18-
// phpcs:disable
19-
public $fields = [
20-
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
21-
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
22-
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
23-
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
24-
'_indexes' => [
25-
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
26-
],
27-
'_constraints' => [
28-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
29-
],
30-
'_options' => [
31-
'engine' => 'InnoDB',
32-
'collation' => 'latin1_swedish_ci'
33-
],
34-
];
35-
// phpcs:enable
3611
/**
3712
* Init method
3813
*
@@ -46,60 +21,90 @@ public function init(): void
4621
'first_name' => 'PENELOPE',
4722
'last_name' => 'GUINESS',
4823
'modified' => '2006-02-15 04:34:33',
24+
'write' => 'wo',
25+
'read' => 'ro',
26+
'hide' => 'hidden',
4927
],
5028
[
5129
'id' => '2',
5230
'first_name' => 'NICK',
5331
'last_name' => 'WAHLBERG',
5432
'modified' => '2006-02-15 04:34:33',
33+
'write' => 'wo',
34+
'read' => 'ro',
35+
'hide' => 'hidden',
5536
],
5637
[
5738
'id' => '3',
5839
'first_name' => 'ED',
5940
'last_name' => 'CHASE',
6041
'modified' => '2006-02-15 04:34:33',
42+
'write' => 'wo',
43+
'read' => 'ro',
44+
'hide' => 'hidden',
6145
],
6246
[
6347
'id' => '4',
6448
'first_name' => 'JENNIFER',
6549
'last_name' => 'DAVIS',
6650
'modified' => '2006-02-15 04:34:33',
51+
'write' => 'wo',
52+
'read' => 'ro',
53+
'hide' => 'hidden',
6754
],
6855
[
6956
'id' => '5',
7057
'first_name' => 'JOHNNY',
7158
'last_name' => 'LOLLOBRIGIDA',
7259
'modified' => '2006-02-15 04:34:33',
60+
'write' => 'wo',
61+
'read' => 'ro',
62+
'hide' => 'hidden',
7363
],
7464
[
7565
'id' => '6',
7666
'first_name' => 'BETTE',
7767
'last_name' => 'NICHOLSON',
7868
'modified' => '2006-02-15 04:34:33',
69+
'write' => 'wo',
70+
'read' => 'ro',
71+
'hide' => 'hidden',
7972
],
8073
[
8174
'id' => '7',
8275
'first_name' => 'GRACE',
8376
'last_name' => 'MOSTEL',
8477
'modified' => '2006-02-15 04:34:33',
78+
'write' => 'wo',
79+
'read' => 'ro',
80+
'hide' => 'hidden',
8581
],
8682
[
8783
'id' => '8',
8884
'first_name' => 'MATTHEW',
8985
'last_name' => 'JOHANSSON',
9086
'modified' => '2006-02-15 04:34:33',
87+
'write' => 'wo',
88+
'read' => 'ro',
89+
'hide' => 'hidden',
9190
],
9291
[
9392
'id' => '9',
9493
'first_name' => 'JOE',
9594
'last_name' => 'SWANK',
9695
'modified' => '2006-02-15 04:34:33',
96+
'write' => 'wo',
97+
'read' => 'ro',
98+
'hide' => 'hidden',
9799
],
98100
[
99101
'id' => '10',
100102
'first_name' => 'CHRISTIAN',
101103
'last_name' => 'GABLE',
102104
'modified' => '2006-02-15 04:34:33',
105+
'write' => 'wo',
106+
'read' => 'ro',
107+
'hide' => 'hidden',
103108
],
104109
];
105110
parent::init();

plugins/core/tests/TestCase/Model/ModelTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,24 @@ public function test_model_property(): void
4444
))->create();
4545

4646
$this->assertTrue($model->getProperty('id')->isPrimaryKey());
47+
$this->assertFalse($model->getProperty('id')->isAccessible());
48+
4749
$this->assertEmpty($model->getProperty('first_name')->getDefault());
4850
$this->assertFalse($model->getProperty('first_name')->isHidden());
4951
$this->assertTrue($model->getProperty('first_name')->isAccessible());
52+
5053
$this->assertEquals('string', $model->getProperty('first_name')->getType());
5154
$this->assertEquals('first_name', $model->getProperty('first_name')->getName());
5255
$this->assertInstanceOf(ValidationSet::class, $model->getProperty('first_name')->getValidationSet());
5356

57+
$this->assertTrue($model->getProperty('write')->isAccessible());
58+
$this->assertTrue($model->getProperty('write')->isHidden());
59+
60+
$this->assertFalse($model->getProperty('read')->isAccessible());
61+
$this->assertFalse($model->getProperty('read')->isHidden());
62+
63+
$this->assertTrue($model->getProperty('hide')->isHidden());
64+
5465
$this->expectException(\InvalidArgumentException::class);
5566
$model->getProperty('does_not_exist');
5667
}

plugins/core/tests/bootstrap.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* For full copyright and license information, please see the LICENSE.txt
10+
* Redistributions of files must retain the above copyright notice.
11+
*
12+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
13+
* @link https://cakephp.org CakePHP(tm) Project
14+
* @since 3.0.0
15+
* @license https://opensource.org/licenses/mit-license.php MIT License
16+
*/
17+
18+
use Cake\Core\Configure;
19+
use Cake\Datasource\ConnectionManager;
20+
21+
/**
22+
* Test runner bootstrap.
23+
*
24+
* Add additional configuration/setup your application needs when running
25+
* unit tests in this file.
26+
*/
27+
require dirname(__DIR__) . '/vendor/autoload.php';
28+
29+
require dirname(__DIR__) . '/config/bootstrap.php';
30+
31+
$_SERVER['PHP_SELF'] = '/';
32+
33+
define('IS_TEST', true);
34+
35+
Configure::write('App.fullBaseUrl', 'http://localhost');
36+
putenv('DB=sqlite');
37+
38+
// Fixate sessionid early on, as php7.2+
39+
// does not allow the sessionid to be set after stdout
40+
// has been written to.
41+
session_id('cli');

plugins/core/tests/test_app/src/Model/Entity/Actor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ class Actor extends Entity
2020
protected $_accessible = [
2121
'first_name' => true,
2222
'last_name' => true,
23+
'write' => true,
2324
'*' => false
2425
];
2526

27+
protected $_hidden = [
28+
'hide', 'write'
29+
];
30+
2631
/**
2732
* @param EntityInterface $entity
2833
* @return array|\string[][]

plugins/crud/tests/Fixture/ActorsFixture.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,11 @@
33

44
namespace MixerApi\Crud\Test\Fixture;
55

6-
use Cake\TestSuite\Fixture\TestFixture;
7-
86
/**
97
* ActorsFixture
108
*/
11-
class ActorsFixture extends TestFixture
9+
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
1210
{
13-
/**
14-
* Fields
15-
*
16-
* @var array
17-
*/
18-
// phpcs:disable
19-
public $fields = [
20-
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
21-
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
22-
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
23-
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
24-
'_indexes' => [
25-
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
26-
],
27-
'_constraints' => [
28-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
29-
],
30-
'_options' => [
31-
'engine' => 'InnoDB',
32-
'collation' => 'latin1_swedish_ci'
33-
],
34-
];
35-
// phpcs:enable
3611
/**
3712
* Init method
3813
*

plugins/crud/tests/bootstrap.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* For full copyright and license information, please see the LICENSE.txt
10+
* Redistributions of files must retain the above copyright notice.
11+
*
12+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
13+
* @link https://cakephp.org CakePHP(tm) Project
14+
* @since 3.0.0
15+
* @license https://opensource.org/licenses/mit-license.php MIT License
16+
*/
17+
18+
use Cake\Core\Configure;
19+
use Cake\Datasource\ConnectionManager;
20+
21+
/**
22+
* Test runner bootstrap.
23+
*
24+
* Add additional configuration/setup your application needs when running
25+
* unit tests in this file.
26+
*/
27+
require dirname(__DIR__) . '/vendor/autoload.php';
28+
29+
require dirname(__DIR__) . '/config/bootstrap.php';
30+
31+
$_SERVER['PHP_SELF'] = '/';
32+
33+
define('IS_TEST', true);
34+
35+
Configure::write('App.fullBaseUrl', 'http://localhost');
36+
putenv('DB=sqlite');
37+
38+
// Fixate sessionid early on, as php7.2+
39+
// does not allow the sessionid to be set after stdout
40+
// has been written to.
41+
session_id('cli');

0 commit comments

Comments
 (0)