Skip to content

Commit

Permalink
6 fientries update connector (#7)
Browse files Browse the repository at this point in the history
Added feature to have the type of entity to create, update or delete be different from the connector type.

This fixes an issue with providing data for the UpdateConnector 'FiEntries', whose type of entity to create must be 'FiEntryPar'.

Co-authored-by: Peter Kok <[email protected]>
Co-authored-by: MegaChriz <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2022
1 parent b6b17d8 commit 487c2c0
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/Core/Query/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class Delete extends UpdateBase implements DeleteInterface {
* The data to delete.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity to delete.
*/
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = []) {
parent::__construct($server, $connector_id, $data, $attribute_keys);
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
parent::__construct($server, $connector_id, $data, $attribute_keys, $entity_type_id);
$this->entityContainer->setAction(EntityInterface::FIELDS_DELETE);
$this->entityContainer->fromArray($data);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Core/Query/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class Insert extends UpdateBase implements InsertInterface {
* The data to insert.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity to insert.
*/
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = []) {
parent::__construct($server, $connector_id, $data, $attribute_keys);
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
parent::__construct($server, $connector_id, $data, $attribute_keys, $entity_type_id);
$this->entityContainer->fromArray($data);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Core/Query/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class Update extends UpdateBase implements UpdateInterface {
* The data to update.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity to update.
*/
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = []) {
parent::__construct($server, $connector_id, $data, $attribute_keys);
public function __construct(ServerInterface $server, $connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
parent::__construct($server, $connector_id, $data, $attribute_keys, $entity_type_id);
$this->entityContainer->setAction(EntityInterface::FIELDS_UPDATE);
$this->entityContainer->fromArray($data);
}
Expand Down
14 changes: 12 additions & 2 deletions src/Core/Query/UpdateBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class UpdateBase extends Query implements UpdateBaseInterface {
*/
protected $connectorId;

/**
* The type of entity to insert, update or delete.
*
* @var string
*/
protected $entityTypeId;

/**
* An entity container.
*
Expand All @@ -41,11 +48,14 @@ class UpdateBase extends Query implements UpdateBaseInterface {
* The data to update.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity to insert, update or delete.
*/
public function __construct(ServerInterface $server, $connector_id, array &$data, array $attribute_keys = []) {
public function __construct(ServerInterface $server, $connector_id, array &$data, array $attribute_keys = [], string $entity_type_id = '') {
parent::__construct($server);
$this->connectorId = $connector_id;
$this->entityContainer = new EntityContainer($connector_id);
$this->entityTypeId = $entity_type_id ?: $connector_id;
$this->entityContainer = new EntityContainer($this->entityTypeId);

if (!empty($attribute_keys)) {
if (ArrayHelper::isAssociative($data)) {
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ public function get($connector_id) {
/**
* {@inheritdoc}
*/
public function insert($connector_id, array $data, array $attribute_keys = []) {
return new Insert($this, $connector_id, $data, $attribute_keys);
public function insert($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
return new Insert($this, $connector_id, $data, $attribute_keys, $entity_type_id);
}

/**
* {@inheritdoc}
*/
public function update($connector_id, array $data, array $attribute_keys = []) {
return new Update($this, $connector_id, $data, $attribute_keys);
public function update($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
return new Update($this, $connector_id, $data, $attribute_keys, $entity_type_id);
}

/**
* {@inheritdoc}
*/
public function delete($connector_id, array $data, array $attribute_keys = []) {
return new Delete($this, $connector_id, $data, $attribute_keys);
public function delete($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '') {
return new Delete($this, $connector_id, $data, $attribute_keys, $entity_type_id);
}

// --------------------------------------------------------------
Expand Down
12 changes: 9 additions & 3 deletions src/Core/ServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public function get($connector_id);
* The data to insert.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity that needs to be inserted.
*
* @return \Afas\Core\Query\Insert
* An insert query.
*/
public function insert($connector_id, array $data, array $attribute_keys = []);
public function insert($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '');

/**
* Returns an update query object.
Expand All @@ -46,11 +48,13 @@ public function insert($connector_id, array $data, array $attribute_keys = []);
* The data to update.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity that needs to be updated.
*
* @return \Afas\Core\Query\Update
* An update query.
*/
public function update($connector_id, array $data, array $attribute_keys = []);
public function update($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '');

/**
* Returns an update query object.
Expand All @@ -61,11 +65,13 @@ public function update($connector_id, array $data, array $attribute_keys = []);
* The data to delete.
* @param array $attribute_keys
* (optional) The keys belonging to attributes.
* @param string $entity_type_id
* (optional) The type of entity that needs to be deleted.
*
* @return \Afas\Core\Query\Delete
* A delete query.
*/
public function delete($connector_id, array $data, array $attribute_keys = []);
public function delete($connector_id, array $data, array $attribute_keys = [], string $entity_type_id = '');

// --------------------------------------------------------------
// GETTERS
Expand Down
114 changes: 114 additions & 0 deletions tests/src/Core/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,44 @@ public function testInsertWithAttributes() {
$this->assertXmlStringEqualsXmlString($expected, $insert->getEntityContainer()->compile());
}

/**
* @covers ::insert
*/
public function testInsertWithEntityTypeId() {
$insert = $this->server->insert('Dummy', [
'DbId' => 12345,
], [], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="insert">
<DbId>12345</DbId>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $insert->getEntityContainer()->compile());
}

/**
* @covers ::insert
*/
public function testInsertWithAttributesAndEntityTypeId() {
$insert = $this->server->insert('Dummy', [
'DbId' => 12345,
'CdId' => 10001,
'Foo' => 'Bar',
], ['DbId', 'CdId'], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element DbId="12345" CdId="10001">
<Fields Action="insert">
<Foo>Bar</Foo>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $insert->getEntityContainer()->compile());
}

/**
* @covers ::update
*/
Expand Down Expand Up @@ -128,6 +166,44 @@ public function testUpdateWithAttributes() {
$this->assertXmlStringEqualsXmlString($expected, $update->getEntityContainer()->compile());
}

/**
* @covers ::update
*/
public function testUpdateWithEntityTypeId() {
$update = $this->server->update('Dummy', [
'DbId' => 12345,
], [], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="update">
<DbId>12345</DbId>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $update->getEntityContainer()->compile());
}

/**
* @covers ::update
*/
public function testUpdateWithAttributesAndEntityTypeId() {
$update = $this->server->update('Dummy', [
'DbId' => 12345,
'CdId' => 10001,
'Foo' => 'Bar',
], ['DbId', 'CdId'], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element DbId="12345" CdId="10001">
<Fields Action="update">
<Foo>Bar</Foo>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $update->getEntityContainer()->compile());
}

/**
* @covers ::delete
*/
Expand Down Expand Up @@ -173,6 +249,44 @@ public function testDeleteWithAttributes() {
$this->assertXmlStringEqualsXmlString($expected, $delete->getEntityContainer()->compile());
}

/**
* @covers ::delete
*/
public function testDeleteWithEntityTypeId() {
$delete = $this->server->delete('Dummy', [
'DbId' => 12345,
], [], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="delete">
<DbId>12345</DbId>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $delete->getEntityContainer()->compile());
}

/**
* @covers ::delete
*/
public function testDeleteWithAttributesAndEntityTypeId() {
$delete = $this->server->delete('Dummy', [
'DbId' => 12345,
'CdId' => 10001,
'Foo' => 'Bar',
], ['DbId', 'CdId'], 'Dummy2');

$expected = '<Dummy2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element DbId="12345" CdId="10001">
<Fields Action="delete">
<Foo>Bar</Foo>
</Fields>
</Element>
</Dummy2>';
$this->assertXmlStringEqualsXmlString($expected, $delete->getEntityContainer()->compile());
}

/**
* @covers ::getBaseUrl
* @covers ::__construct
Expand Down

0 comments on commit 487c2c0

Please sign in to comment.