These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\FormBundle\Tests\Entity\FormSubmissionFieldTypes; |
||
4 | |||
5 | use Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\FileFormSubmissionField; |
||
6 | use Kunstmaan\FormBundle\Form\FileFormSubmissionType; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use Symfony\Component\DependencyInjection\Container; |
||
9 | use Symfony\Component\Form\Form; |
||
10 | use Symfony\Component\Form\FormBuilder; |
||
11 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||
12 | use Symfony\Component\HttpFoundation\Request; |
||
13 | |||
14 | /** |
||
15 | * Tests for FileFormSubmissionField |
||
16 | */ |
||
17 | class FileFormSubmissionFieldTest extends TestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var FileFormSubmissionField |
||
21 | */ |
||
22 | protected $object; |
||
23 | |||
24 | /** |
||
25 | * Sets up the fixture, for example, opens a network connection. |
||
26 | * This method is called before a test is executed. |
||
27 | */ |
||
28 | protected function setUp() |
||
29 | { |
||
30 | $this->object = new FileFormSubmissionField(); |
||
31 | } |
||
32 | |||
33 | public function testToString() |
||
34 | { |
||
35 | $stringValue = $this->object->__toString(); |
||
36 | $this->assertNotNull($stringValue); |
||
37 | $this->assertInternalType('string', $stringValue); |
||
0 ignored issues
–
show
|
|||
38 | } |
||
39 | |||
40 | public function testIsNull() |
||
41 | { |
||
42 | $file = new UploadedFile(__DIR__ . '/../../Resources/assets/example.jpg', 'example.jpg'); |
||
43 | |||
44 | $object = $this->object; |
||
45 | $this->assertTrue($object->isNull()); |
||
46 | $object->file = $file; |
||
47 | $this->assertFalse($object->isNull()); |
||
48 | } |
||
49 | |||
50 | public function testGetSafeFileName() |
||
51 | { |
||
52 | $file = new UploadedFile(__DIR__ . '/../../Resources/assets/example.jpg', 'the file name $@&.jpg'); |
||
53 | |||
54 | $object = $this->object; |
||
55 | $object->file = $file; |
||
56 | $safeName = $object->getSafeFileName(); |
||
57 | |||
58 | $this->assertEquals('the-file-name.jpeg', $safeName); |
||
59 | } |
||
60 | |||
61 | public function testGettersAndSetters() |
||
62 | { |
||
63 | $object = $this->object; |
||
64 | $fileName = 'test.jpg'; |
||
65 | $object->setFileName($fileName); |
||
66 | $object->setUrl('https://nasa.gov'); |
||
67 | $object->setUuid('123'); |
||
68 | |||
69 | $this->assertEquals($fileName, $object->getFileName()); |
||
70 | $this->assertEquals('https://nasa.gov', $object->getUrl()); |
||
71 | $this->assertEquals('123', $object->getUuid()); |
||
72 | $this->assertEquals(FileFormSubmissionType::class, $object->getDefaultAdminType()); |
||
73 | } |
||
74 | |||
75 | public function testGetSubmissionTemplate() |
||
76 | { |
||
77 | $template = $this->object->getSubmissionTemplate(); |
||
78 | $this->assertNotNull($template); |
||
79 | } |
||
80 | |||
81 | public function testUpload() |
||
82 | { |
||
83 | $object = $this->object; |
||
84 | $this->assertNull($object->upload('..', '..')); |
||
85 | |||
86 | $file = $this->getMockBuilder(UploadedFile::class) |
||
87 | ->disableOriginalConstructor() |
||
88 | ->getMock(); |
||
89 | |||
90 | $file->expects($this->any()) |
||
91 | ->method('move') |
||
92 | ->willReturn(true); |
||
93 | |||
94 | $object->file = $file; |
||
95 | $object->upload(__DIR__ . '/../../Resources/assets/', __DIR__ . '/../../Resources/assets/'); |
||
96 | |||
97 | $form = $this->getMockBuilder(Form::class) |
||
98 | ->disableOriginalConstructor() |
||
99 | ->getMock(); |
||
100 | |||
101 | $builder = $this->getMockBuilder(FormBuilder::class) |
||
102 | ->disableOriginalConstructor() |
||
103 | ->getMock(); |
||
104 | |||
105 | $request = new Request(); |
||
106 | |||
107 | $container = $this->getMockBuilder(Container::class) |
||
108 | ->disableOriginalConstructor() |
||
109 | ->getMock(); |
||
110 | |||
111 | $container->expects($this->any()) |
||
112 | ->method('getParameter') |
||
113 | ->willReturn('whatever'); |
||
114 | |||
115 | $object->onValidPost($form, $builder, $request, $container); |
||
116 | } |
||
117 | } |
||
118 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.