Skip to content

[Core] - Show hidden properties #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions plugins/bake/tests/Fixture/ActorsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,8 @@
/**
* ActorsFixture
*/
class ActorsFixture extends TestFixture
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
{
/**
* Fields
*
* @var array
*/
// phpcs:disable
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
'_indexes' => [
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'latin1_swedish_ci'
],
];
// phpcs:enable
/**
* Init method
*
Expand Down
25 changes: 1 addition & 24 deletions plugins/collection-view/tests/Fixture/ActorsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,8 @@
/**
* ActorsFixture
*/
class ActorsFixture extends TestFixture
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
{
/**
* Fields
*
* @var array
*/
// phpcs:disable
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
'_indexes' => [
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'latin1_swedish_ci'
],
];
// phpcs:enable
/**
* Init method
*
Expand Down
9 changes: 1 addition & 8 deletions plugins/core/src/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,9 @@ public function getProperty(string $columnName): ModelProperty
*/
private function assignProperties(): void
{
$hiddenAttributes = $this->entity->getHidden();

$columns = array_filter($this->schema->columns(), function ($column) use ($hiddenAttributes) {
return !in_array($column, $hiddenAttributes) ? true : null;
});

foreach ($columns as $columnName) {
foreach ($this->schema->columns() as $columnName) {
$modelProperty = (new ModelPropertyFactory($this->schema, $this->table, $columnName, $this->entity))
->create();

$this->properties[$columnName] = $modelProperty;
}
}
Expand Down
57 changes: 31 additions & 26 deletions plugins/core/tests/Fixture/ActorsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,11 @@

namespace MixerApi\Core\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ActorsFixture
*/
class ActorsFixture extends TestFixture
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
{
/**
* Fields
*
* @var array
*/
// phpcs:disable
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
'_indexes' => [
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'latin1_swedish_ci'
],
];
// phpcs:enable
/**
* Init method
*
Expand All @@ -46,60 +21,90 @@ public function init(): void
'first_name' => 'PENELOPE',
'last_name' => 'GUINESS',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '2',
'first_name' => 'NICK',
'last_name' => 'WAHLBERG',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '3',
'first_name' => 'ED',
'last_name' => 'CHASE',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '4',
'first_name' => 'JENNIFER',
'last_name' => 'DAVIS',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '5',
'first_name' => 'JOHNNY',
'last_name' => 'LOLLOBRIGIDA',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '6',
'first_name' => 'BETTE',
'last_name' => 'NICHOLSON',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '7',
'first_name' => 'GRACE',
'last_name' => 'MOSTEL',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '8',
'first_name' => 'MATTHEW',
'last_name' => 'JOHANSSON',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '9',
'first_name' => 'JOE',
'last_name' => 'SWANK',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
[
'id' => '10',
'first_name' => 'CHRISTIAN',
'last_name' => 'GABLE',
'modified' => '2006-02-15 04:34:33',
'write' => 'wo',
'read' => 'ro',
'hide' => 'hidden',
],
];
parent::init();
Expand Down
11 changes: 11 additions & 0 deletions plugins/core/tests/TestCase/Model/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,24 @@ public function test_model_property(): void
))->create();

$this->assertTrue($model->getProperty('id')->isPrimaryKey());
$this->assertFalse($model->getProperty('id')->isAccessible());

$this->assertEmpty($model->getProperty('first_name')->getDefault());
$this->assertFalse($model->getProperty('first_name')->isHidden());
$this->assertTrue($model->getProperty('first_name')->isAccessible());

$this->assertEquals('string', $model->getProperty('first_name')->getType());
$this->assertEquals('first_name', $model->getProperty('first_name')->getName());
$this->assertInstanceOf(ValidationSet::class, $model->getProperty('first_name')->getValidationSet());

$this->assertTrue($model->getProperty('write')->isAccessible());
$this->assertTrue($model->getProperty('write')->isHidden());

$this->assertFalse($model->getProperty('read')->isAccessible());
$this->assertFalse($model->getProperty('read')->isHidden());

$this->assertTrue($model->getProperty('hide')->isHidden());

$this->expectException(\InvalidArgumentException::class);
$model->getProperty('does_not_exist');
}
Expand Down
41 changes: 41 additions & 0 deletions plugins/core/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;

/**
* Test runner bootstrap.
*
* Add additional configuration/setup your application needs when running
* unit tests in this file.
*/
require dirname(__DIR__) . '/vendor/autoload.php';

require dirname(__DIR__) . '/config/bootstrap.php';

$_SERVER['PHP_SELF'] = '/';

define('IS_TEST', true);

Configure::write('App.fullBaseUrl', 'http://localhost');
putenv('DB=sqlite');

// Fixate sessionid early on, as php7.2+
// does not allow the sessionid to be set after stdout
// has been written to.
session_id('cli');
5 changes: 5 additions & 0 deletions plugins/core/tests/test_app/src/Model/Entity/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class Actor extends Entity
protected $_accessible = [
'first_name' => true,
'last_name' => true,
'write' => true,
'*' => false
];

protected $_hidden = [
'hide', 'write'
];

/**
* @param EntityInterface $entity
* @return array|\string[][]
Expand Down
27 changes: 1 addition & 26 deletions plugins/crud/tests/Fixture/ActorsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,11 @@

namespace MixerApi\Crud\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ActorsFixture
*/
class ActorsFixture extends TestFixture
class ActorsFixture extends \App\Test\Fixture\ActorsFixture
{
/**
* Fields
*
* @var array
*/
// phpcs:disable
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'first_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'last_name' => ['type' => 'string', 'length' => 45, 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'comment' => '', 'precision' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'precision' => null, 'null' => false, 'default' => null, 'comment' => ''],
'_indexes' => [
'last_name' => ['type' => 'index', 'columns' => ['last_name'], 'length' => []],
],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'latin1_swedish_ci'
],
];
// phpcs:enable
/**
* Init method
*
Expand Down
41 changes: 41 additions & 0 deletions plugins/crud/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;

/**
* Test runner bootstrap.
*
* Add additional configuration/setup your application needs when running
* unit tests in this file.
*/
require dirname(__DIR__) . '/vendor/autoload.php';

require dirname(__DIR__) . '/config/bootstrap.php';

$_SERVER['PHP_SELF'] = '/';

define('IS_TEST', true);

Configure::write('App.fullBaseUrl', 'http://localhost');
putenv('DB=sqlite');

// Fixate sessionid early on, as php7.2+
// does not allow the sessionid to be set after stdout
// has been written to.
session_id('cli');
Loading