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\Services; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use App\Entity\Attachments\AttachmentType; |
26
|
|
|
use App\Services\AmountFormatter; |
27
|
|
|
use App\Services\ElementTypeNameGenerator; |
28
|
|
|
use App\Services\EntityImporter; |
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
30
|
|
|
|
31
|
|
|
class EntityImporterTest extends WebTestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var AmountFormatter |
35
|
|
|
*/ |
36
|
|
|
protected $service; |
37
|
|
|
|
38
|
|
|
public function setUp() |
39
|
|
|
{ |
40
|
|
|
parent::setUp(); |
41
|
|
|
|
42
|
|
|
//Get an service instance. |
43
|
|
|
self::bootKernel(); |
44
|
|
|
$this->service = self::$container->get(EntityImporter::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testMassCreationResults() |
48
|
|
|
{ |
49
|
|
|
$errors = []; |
50
|
|
|
$results = $this->service->massCreation('', AttachmentType::class, null, $errors); |
|
|
|
|
51
|
|
|
$this->assertEmpty($results); |
52
|
|
|
$this->assertEmpty($errors); |
53
|
|
|
|
54
|
|
|
$errors = []; |
55
|
|
|
$lines = "Test 1 \n Test 2 \n Test 3"; |
56
|
|
|
$results = $this->service->massCreation($lines, AttachmentType::class, null, $errors); |
57
|
|
|
$this->assertCount(0, $errors); |
58
|
|
|
$this->assertCount(3, $results); |
59
|
|
|
//Check type |
60
|
|
|
$this->assertInstanceOf(AttachmentType::class, $results[0]); |
61
|
|
|
//Check names |
62
|
|
|
$this->assertEquals('Test 1', $results[0]->getName()); |
63
|
|
|
$this->assertEquals('Test 2', $results[1]->getName()); |
64
|
|
|
//Check parent |
65
|
|
|
$this->assertNull($results[0]->getMasterPictureAttachment()); |
66
|
|
|
|
67
|
|
|
$parent = new AttachmentType(); |
68
|
|
|
$results = $this->service->massCreation($lines, AttachmentType::class, $parent, $errors); |
69
|
|
|
$this->assertCount(3, $results); |
70
|
|
|
$this->assertEquals($parent, $results[0]->getParent()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testMassCreationErrors() |
74
|
|
|
{ |
75
|
|
|
$errors = []; |
76
|
|
|
//Node 1 and Node 2 are created in datafixtures, so their attemp to create them again must fail. |
77
|
|
|
$lines = "Test 1 \n Node 1 \n Node 2"; |
78
|
|
|
$results = $this->service->massCreation($lines, AttachmentType::class, null, $errors); |
79
|
|
|
$this->assertCount(1, $results); |
80
|
|
|
$this->assertEquals('Test 1', $results[0]->getName()); |
81
|
|
|
$this->assertCount(2, $errors); |
82
|
|
|
$this->assertEquals('Node 1', $errors[0]['entity']->getName()); |
83
|
|
|
} |
84
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.