Skip to content
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
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Bake">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
<arg value="ns"/>

<file>src/</file>
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/BakeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function columnData(string $field, TableSchema $schema): ?array
public function enumSupportsLabel(string $field, TableSchema $schema): bool
{
$typeName = $schema->getColumnType($field);
if (!str_starts_with($typeName, 'enum-')) {
if (!$typeName || !str_starts_with($typeName, 'enum-')) {
return false;
}
$type = TypeFactory::build($typeName);
Expand Down
28 changes: 21 additions & 7 deletions tests/TestCase/View/Helper/BakeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/
namespace Bake\Test\TestCase\View\Helper;

use Bake\Test\App\Model\Enum\BakeUserStatus;
use Bake\View\BakeView;
use Bake\View\Helper\BakeHelper;
use Cake\Database\Type\EnumType;
use Cake\Http\Response;
use Cake\Http\ServerRequest as Request;
use Cake\TestSuite\TestCase;
Expand All @@ -40,6 +42,7 @@ class BakeHelperTest extends TestCase
'plugin.Bake.BakeComments',
'plugin.Bake.BakeArticlesBakeTags',
'plugin.Bake.BakeTags',
'plugin.Bake.Users',
];

/**
Expand Down Expand Up @@ -89,12 +92,12 @@ public function testAliasExtractorFilteredHasMany()
'className' => '\Bake\Test\App\Model\Table\ArticlesTable',
]);
$this->BakeHelper = $this->getMockBuilder('Bake\View\Helper\BakeHelper')
->disableOriginalConstructor()
->onlyMethods(['_filterHasManyAssociationsAliases'])
->getMock();
->disableOriginalConstructor()
->onlyMethods(['_filterHasManyAssociationsAliases'])
->getMock();
$this->BakeHelper->expects($this->once())
->method('_filterHasManyAssociationsAliases')
->with($table, ['ArticlesTags']);
->method('_filterHasManyAssociationsAliases')
->with($table, ['ArticlesTags']);
$result = $this->BakeHelper->aliasExtractor($table, 'HasMany');
$this->assertEmpty($result);
}
Expand All @@ -107,7 +110,7 @@ public function testAliasExtractorFilteredHasMany()
public function testAliasExtractorBelongsTo()
{
$table = $this->getTableLocator()->get('Articles', [
'className' => '\Bake\Test\App\Model\Table\ArticlesTable',
'className' => '\Bake\Test\App\Model\Table\ArticlesTable',
]);
$result = $this->BakeHelper->aliasExtractor($table, 'BelongsTo');
$expected = ['authors'];
Expand All @@ -122,7 +125,7 @@ public function testAliasExtractorBelongsTo()
public function testAliasExtractorBelongsToMany()
{
$table = $this->getTableLocator()->get('Articles', [
'className' => '\Bake\Test\App\Model\Table\ArticlesTable',
'className' => '\Bake\Test\App\Model\Table\ArticlesTable',
]);
$result = $this->BakeHelper->aliasExtractor($table, 'BelongsToMany');
$expected = ['tags'];
Expand Down Expand Up @@ -185,4 +188,15 @@ public function testHasPlugin(): void
$this->assertTrue($this->BakeHelper->hasPlugin('Bake'));
$this->assertFalse($this->BakeHelper->hasPlugin('DebugKit'));
}

public function testEnumSupportsLabel(): void
{
$table = $this->fetchTable('BakeUsers');
$schema = $table->getSchema();
$schema->setColumnType('status', EnumType::from(BakeUserStatus::class));

$this->assertTrue($this->BakeHelper->enumSupportsLabel('status', $schema));
$this->assertFalse($this->BakeHelper->enumSupportsLabel('username', $schema));
$this->assertFalse($this->BakeHelper->enumSupportsLabel('does_not_exist', $schema));
}
}