1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace App\Tests\Security\Annotations; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use App\Entity\Attachments\AttachmentType; |
26
|
|
|
use App\Security\Annotations\ColumnSecurity; |
27
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
28
|
|
|
|
29
|
|
|
class ColumnSecurityTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
public function testGetReadOperation() |
32
|
|
|
{ |
33
|
|
|
$annotation = new ColumnSecurity(); |
34
|
|
|
$this->assertEquals('read', $annotation->getReadOperationName(), 'A new annotation must return read'); |
35
|
|
|
$annotation->read = 'overwritten'; |
36
|
|
|
$this->assertEquals('overwritten', $annotation->getReadOperationName()); |
37
|
|
|
$annotation->prefix = 'prefix'; |
38
|
|
|
$this->assertEquals('prefix.overwritten', $annotation->getReadOperationName()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetEditOperation() |
42
|
|
|
{ |
43
|
|
|
$annotation = new ColumnSecurity(); |
44
|
|
|
$this->assertEquals('edit', $annotation->getEditOperationName(), 'A new annotation must return read'); |
45
|
|
|
$annotation->edit = 'overwritten'; |
46
|
|
|
$this->assertEquals('overwritten', $annotation->getEditOperationName()); |
47
|
|
|
$annotation->prefix = 'prefix'; |
48
|
|
|
$this->assertEquals('prefix.overwritten', $annotation->getEditOperationName()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function placeholderScalarDataProvider() : array |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
['string', '???'], |
55
|
|
|
['integer', 0], |
56
|
|
|
['int', 0], |
57
|
|
|
['float', 0.0], |
58
|
|
|
['object', null], |
59
|
|
|
['bool', false], |
60
|
|
|
['boolean', false], |
61
|
|
|
//['datetime', (new \DateTime())->setTimestamp(0)] |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider placeholderScalarDataProvider |
67
|
|
|
* @param string $type |
68
|
|
|
* @param $expected_value |
69
|
|
|
*/ |
70
|
|
|
public function testGetPlaceholderScalar(string $type, $expected_value) |
71
|
|
|
{ |
72
|
|
|
$annotation = new ColumnSecurity(); |
73
|
|
|
$annotation->type = $type; |
74
|
|
|
$this->assertEquals($expected_value, $annotation->getPlaceholder()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testGetPlaceholderSpecifiedValue() |
78
|
|
|
{ |
79
|
|
|
$annotation = new ColumnSecurity(); |
80
|
|
|
$annotation->placeholder = 3434; |
81
|
|
|
$this->assertEquals(3434, $annotation->getPlaceholder()); |
82
|
|
|
|
83
|
|
|
$annotation->placeholder = [323]; |
|
|
|
|
84
|
|
|
$this->assertCount(1, $annotation->getPlaceholder()); |
85
|
|
|
|
86
|
|
|
//If a placeholder is specified we allow every type |
87
|
|
|
$annotation->type = "type2"; |
88
|
|
|
$annotation->placeholder = 'invalid'; |
89
|
|
|
$this->assertEquals('invalid', $annotation->getPlaceholder()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetPlaceholderDBElement() |
93
|
|
|
{ |
94
|
|
|
$annotation = new ColumnSecurity(); |
95
|
|
|
$annotation->type = AttachmentType::class; |
96
|
|
|
|
97
|
|
|
/** @var AttachmentType $placeholder */ |
98
|
|
|
$placeholder = $annotation->getPlaceholder(); |
99
|
|
|
$this->assertInstanceOf(AttachmentType::class, $placeholder); |
100
|
|
|
$this->assertEquals('???', $placeholder->getName()); |
101
|
|
|
|
102
|
|
|
$annotation->placeholder = 'test'; |
103
|
|
|
$placeholder = $annotation->getPlaceholder(); |
104
|
|
|
$this->assertInstanceOf(AttachmentType::class, $placeholder); |
105
|
|
|
$this->assertEquals('test', $placeholder->getName()); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths