|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the bitrix24-php-sdk package. |
| 5 | + * |
| 6 | + * © Maksim Mesilov <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the MIT-LICENSE.txt |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Type\Service; |
| 15 | + |
| 16 | +use Bitrix24\SDK\Core\Fields\FieldsFilter; |
| 17 | +use Bitrix24\SDK\Services\CRM\Type\Result\TypeItemResult; |
| 18 | +use Bitrix24\SDK\Services\CRM\Type\Service\Type; |
| 19 | +use Bitrix24\SDK\Tests\Integration\Fabric; |
| 20 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | +use Bitrix24\SDK\Tests\CustomAssertions\CustomBitrix24Assertions; |
| 23 | + |
| 24 | +#[CoversClass(Type::class)] |
| 25 | +class TypeTest extends TestCase |
| 26 | +{ |
| 27 | + use CustomBitrix24Assertions; |
| 28 | + |
| 29 | + protected Type $typeService; |
| 30 | + |
| 31 | + // in response, we have all system fields and some additional system fields |
| 32 | + // public function testAllSystemFieldsAnnotated(): void |
| 33 | + // { |
| 34 | + // $propListFromApi = (new FieldsFilter())->filterSystemFields(array_keys($this->typeService->fields()->getFieldsDescription()['fields'])); |
| 35 | + // $this->assertBitrix24AllResultItemFieldsAnnotated($propListFromApi, TypeItemResult::class); |
| 36 | + // } |
| 37 | + |
| 38 | + public function testAdd(): void |
| 39 | + { |
| 40 | + $title = sprintf('%s test SPA type', time()); |
| 41 | + $result = $this->typeService->add($title); |
| 42 | + $this->assertEquals($title, $result->type()->title); |
| 43 | + $this->assertTrue($this->typeService->delete($result->getId())->isSuccess()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testUpdate(): void |
| 47 | + { |
| 48 | + $title = sprintf('%s test SPA type', time()); |
| 49 | + $result = $this->typeService->add($title); |
| 50 | + $this->assertEquals($title, $result->type()->title); |
| 51 | + |
| 52 | + $title = sprintf('%s updated SPA type', time()); |
| 53 | + $updatedResult = $this->typeService->update($result->getId(), ['title' => $title]); |
| 54 | + $this->assertEquals($title, $updatedResult->type()->title); |
| 55 | + |
| 56 | + $this->assertTrue($this->typeService->delete($result->getId())->isSuccess()); |
| 57 | + } |
| 58 | + |
| 59 | + public function testGet(): void |
| 60 | + { |
| 61 | + $title = sprintf('%s test SPA type', time()); |
| 62 | + $addResult = $this->typeService->add($title); |
| 63 | + |
| 64 | + $result = $this->typeService->get($addResult->getId()); |
| 65 | + $this->assertEquals($title, $addResult->type()->title); |
| 66 | + $this->assertEquals($result->type()->id, $addResult->type()->id); |
| 67 | + $this->assertTrue($this->typeService->delete($addResult->getId())->isSuccess()); |
| 68 | + } |
| 69 | + |
| 70 | + public function testList(): void |
| 71 | + { |
| 72 | + $title = sprintf('%s test SPA type', time()); |
| 73 | + $addResult = $this->typeService->add($title); |
| 74 | + $result = $this->typeService->list([], ['id' => $addResult->getId()])->getTypes()[0]; |
| 75 | + $this->assertEquals($title, $addResult->type()->title); |
| 76 | + $this->assertEquals($result->id, $addResult->type()->id); |
| 77 | + $this->assertTrue($this->typeService->delete($addResult->getId())->isSuccess()); |
| 78 | + } |
| 79 | + |
| 80 | + public function testGetByEntityTypeId(): void |
| 81 | + { |
| 82 | + $title = sprintf('%s test SPA type', time()); |
| 83 | + $result = $this->typeService->add($title); |
| 84 | + $this->assertEquals($title, $result->type()->title); |
| 85 | + |
| 86 | + $resultTypeId = $this->typeService->getByEntityTypeId($result->type()->entityTypeId); |
| 87 | + $this->assertEquals($title, $resultTypeId->type()->title); |
| 88 | + $this->assertEquals($result->type()->id, $resultTypeId->type()->id); |
| 89 | + $this->assertTrue($this->typeService->delete($result->getId())->isSuccess()); |
| 90 | + } |
| 91 | + |
| 92 | + public function testDelete(): void |
| 93 | + { |
| 94 | + $title = sprintf('%s test SPA type', time()); |
| 95 | + $result = $this->typeService->add($title); |
| 96 | + $this->assertEquals($title, $result->type()->title); |
| 97 | + $this->assertTrue($this->typeService->delete($result->getId())->isSuccess()); |
| 98 | + } |
| 99 | + |
| 100 | + protected function setUp(): void |
| 101 | + { |
| 102 | + $this->typeService = Fabric::getServiceBuilder()->getCRMScope()->type(); |
| 103 | + } |
| 104 | +} |
0 commit comments