Skip to content
Snippets Groups Projects
Commit ea7892da authored by damjan's avatar damjan
Browse files

[FEATURE] addNewAttribute service method and its functional test

parent 1e282299
No related branches found
No related tags found
No related merge requests found
......@@ -64,10 +64,10 @@ class Attribute {
*/
private $parent;
/**
* @var ArrayCollection
*/
private $children;
// /**
// * @var ArrayCollection
// */
// private $children;
/**
* @var string
......@@ -215,35 +215,35 @@ class Attribute {
return $this->parent;
}
/**
* Set children
*
* @param ArrayCollection $children
* @return Attribute
*/
public function setChildren($children) {
$this->children = $children;
return $this;
}
/**
* Get children
*
* @return ArrayCollection
*/
public function getChildren() {
return $this->children;
}
/**
* Adds one child to the list.
*
* @param Attribute $child
*/
public function addChild(Attribute $child) {
$this->children[] = $child;
}
// /**
// * Set children
// *
// * @param ArrayCollection $children
// * @return Attribute
// */
// public function setChildren($children) {
// $this->children = $children;
//
// return $this;
// }
//
// /**
// * Get children
// *
// * @return ArrayCollection
// */
// public function getChildren() {
// return $this->children;
// }
//
// /**
// * Adds one child to the list.
// *
// * @param Attribute $child
// */
// public function addChild(Attribute $child) {
// $this->children[] = $child;
// }
/**
* Set isType
......
......@@ -22,6 +22,11 @@ class TsrefRestService {
*/
const TYPO3_DEFAULT_VERSION = '6.2';
/**
* Authentication token
*/
const AUTHENTICATION_TOKEN = 'secretToken'; // TODO: Read it from parameter, and delete this constant.
/**
* Makes curl handle, sets some general options and returns the handle.
* It also checks if cURL is installed.
......@@ -164,8 +169,30 @@ class TsrefRestService {
* Adds new attribute to REST API resource by use of POST method.
*
* @param Attribute $attribute
* @return mixed
*/
public function addNewAttribute(Attribute $attribute) {
$attributeJson = json_encode($attribute);
echo 'AttributeName: ' . $attribute->getName();
echo 'Attribute JSON: ' . $attributeJson;
// json that works example: '{"name":"testNamePUT","description":"Testing PUT modify. cetvrtak","minVersion":"4.2","maxVersion":"7.2","typo3Group":2,"isType":false,"deleted":false, "parent":"181"}'
$curlHandle = $this->initialiseCurl();
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . self::AUTHENTICATION_TOKEN
]);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
return $output;
}
}
\ No newline at end of file
<?php
namespace SGalinski\TypoScriptReferenceFrontend\Service;
// TODO: Fix this autoloading issue and delete these lines.
require_once getcwd() . '/Packages/Application/SGalinski.TypoScriptReferenceFrontend/Classes/SGalinski/TypoScriptReferenceFrontend/Domain/Model/Attribute.php';
require_once getcwd() . '/Packages/Application/SGalinski.TypoScriptReferenceFrontend/Classes/SGalinski/TypoScriptReferenceFrontend/Service/TsrefRestService.php';
require_once getcwd() . '/Packages/Framework/TYPO3.Flow/Tests/BaseTestCase.php';
require_once getcwd() . '/Packages/Framework/TYPO3.Flow/Tests/UnitTestCase.php';
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Attribute;
use TYPO3\Flow\Tests\UnitTestCase;
class TsrefRestServiceTest extends UnitTestCase {
/**
* @var TsrefRestService
*/
protected $tsrefRestService;
/**
* The constructor is used for dependency injection.
*
// * @param TsrefRestService $service
*/
public function __construct(/*TsrefRestService $service*/) {
$this->tsrefRestService = new TsrefRestService();
}
/**
* Creates en Attribute for testing.
*
* @return Attribute
*/
protected function createAttribute() {
$attribute = new Attribute();
$attribute->setName('tsrefTestName');
$attribute->setDescription('This is a test type. Testing addNewAttribute method.');
$attribute->setIsType(TRUE);
$attribute->setTypo3Group(Attribute::USER_GROUP);
$attribute->setMinVersion("2.1");
return $attribute;
}
/**
* Tests \SGalinski\TypoScriptReferenceFrontend\Service\TsrefRestService::addNewAttribute
*
* @test
*/
public function addNewAttributeTest() {
$attribute = $this->createAttribute();
$response = $this->tsrefRestService->addNewAttribute($attribute);
echo ' Response: ' . $response;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment