Skip to content

Commit

Permalink
Merge pull request #808 from oat-sa/release-2.24.0
Browse files Browse the repository at this point in the history
Release 2.24.0
  • Loading branch information
llecaque committed Apr 25, 2016
2 parents 53f9de9 + 4b5cd02 commit adc0dc5
Show file tree
Hide file tree
Showing 31 changed files with 1,929 additions and 184 deletions.
43 changes: 25 additions & 18 deletions actions/class.CommonRestModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function index(){
case "DELETE":{$this->delete($uri);break;}
default:{
throw new common_exception_BadRequest($this->getRequestURI());
;}
}
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ protected function getParameters(){
$effectiveParameters[$checkParameterUri] = $this->getRequestParameter($checkParameterUri);
}
if ($this->isRequiredParameter($checkParameterShort) and !(isset($effectiveParameters[$checkParameterUri]))){
throw new common_exception_MissingParameter($checkParameterShort, $this->getRequestURI());
throw new common_exception_MissingParameter($checkParameterShort, $this->getRequestURI());
}
}
return array_merge($this->getCustomParameters(), $effectiveParameters);
Expand All @@ -262,27 +262,34 @@ private function getCustomParameters(){
}
/**
* Defines if the parameter is mandatory according to getParametersRequirements (probably overriden) and according to the action type
*
* @param type $parameter the alias name or uri of a parameter
* @return bool
*/
private function isRequiredParameter($parameter){

$isRequired = false;
private function isRequiredParameter($parameter)
{
$method = $this->getRequestMethod();//ppl todo, method retrieval
if (isset($requirements[$method])) {
$requirements = $this->getParametersRequirements();
$aliases = $this->getParametersAliases();

$requirements = $this->getParametersRequirements();

//The requirments may have been declared using URIs, loook up for the URI
if (isset($aliases[$parameter])) {
$isRequired = $isRequired or in_array($aliases[$parameter],$requirements[$method]);
$requirements = array_change_key_case($requirements, CASE_LOWER);
$method = strtolower($method);

if (!isset($requirements[$method])) {
return false;
}

$isRequired = $isRequired or in_array($parameter,$requirements[$method]);


}
return $isRequired;
if (in_array($parameter,$requirements[$method])) {
return true;
}

$isRequired = false;

//The requirments may have been declared using URIs, look up for the URI
$aliases = $this->getParametersAliases();
if (isset($aliases[$parameter])) {
$isRequired = in_array($aliases[$parameter],$requirements[$method]);
}
return $isRequired;
}
/**
*
Expand All @@ -295,7 +302,7 @@ private function isRequiredParameter($parameter){

protected function get($uri = null){
try {
if (!is_null($uri)){
if (!is_null($uri)){
if (!common_Utils::isUri($uri)){
throw new common_exception_InvalidArgumentType();
}
Expand Down
13 changes: 13 additions & 0 deletions helpers/class.Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,18 @@ public static function array_unique($array) {
}
return $array;
}

/**
* Test if ann array is associative or not
*
* taken from http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
*
* @param array $arr
* @return boolean
*/
public static function isAssoc($arr)
{
return array_keys($arr) !== range(0, count($arr) - 1);
}

}
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'label' => 'Tao base',
'description' => 'TAO meta-extension',
'license' => 'GPL-2.0',
'version' => '2.23.0',
'version' => '2.24.0',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => array(
'generis' => '>=2.12.0'
Expand Down
24 changes: 18 additions & 6 deletions models/classes/import/class.CSVMappingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function initElements()
if(!isset($this->options['csv_column'])){
throw new Exception('No csv columns found');
}

$columnsOptions = array();
$columnsOptionsLabels = array();
$columnsOptionsLiteral = array();
Expand All @@ -107,7 +107,6 @@ public function initElements()
}
}

$i = 0;
foreach($this->options['class_properties'] as $propertyUri => $propertyLabel){

$propElt = tao_helpers_form_FormFactory::getElement($propertyUri, 'Combobox');
Expand All @@ -119,7 +118,7 @@ public function initElements()
: array_merge($columnsOptionsLiteral, $columnsOptions);

$value = 'csv_select';
if (isset($_POST[$propertyUri]) && isset($columnsOptions[$_POST[$propertyUri]])) {
if (isset($_POST[$propertyUri]) && isset($options[$_POST[$propertyUri]])) {
$value = $_POST[$propertyUri];
}

Expand All @@ -130,9 +129,20 @@ public function initElements()
$propElt->setOptions($options);
$propElt->setValue($value);

/** Add mandatory label */
if (tao_helpers_Uri::decode($propertyUri)==RDFS_LABEL) {
$elementEqualsToCsvSelect = new tao_helpers_form_elements_xhtml_Hidden();
$elementEqualsToCsvSelect->setValue('csv_select');
$elementEqualsToCsvSelect->setDescription(' to null');
$propElt->addValidator(tao_helpers_form_FormFactory::getValidator(
'Equals', array(
'reference' => $elementEqualsToCsvSelect,
'invert' => true
)
));
}

$this->form->addElement($propElt);

$i++;
}
$this->form->createGroup('property_mapping', __('Map the properties to the CSV columns'), array_keys($this->options['class_properties']));

Expand All @@ -143,7 +153,9 @@ public function initElements()
if(!is_null($propElt)){
$defName = tao_helpers_Uri::encode($property->getUri()) . self::DEFAULT_VALUES_SUFFIX;
$propElt->setName($defName);
$propElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
if ($this->form->getElement($propertyUri)->getRawValue()=='csv_null') {
$propElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
}
$this->form->addElement($propElt);
$ranged[$defName] = $propElt;
}
Expand Down
9 changes: 5 additions & 4 deletions models/classes/service/class.StorageDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ public function readStream($path)
* @param mixed $resource
* @return boolean
*/
public function write($path, $resource)
public function write($path, $resource, $mimeType = null)
{
common_Logger::d('Writting in ' . $this->getRelativePath().$path);
return $this->getFileSystem()->writeStream($this->getRelativePath().$path, $resource);
$config = $mimeType = null ? [] : ['ContentType' => $mimeType];
return $this->getFileSystem()->writeStream($this->getRelativePath().$path, $resource, $config);
}

/**
Expand All @@ -146,7 +147,7 @@ public function write($path, $resource)
* @return bool
* @throws common_Exception
*/
public function writeStream($path, StreamInterface $stream)
public function writeStream($path, StreamInterface $stream, $mimeType = null)
{
if (!$stream->isReadable()) {
throw new common_Exception('Stream is not readable. Write to filesystem aborted.');
Expand All @@ -161,7 +162,7 @@ public function writeStream($path, StreamInterface $stream)
throw new common_Exception('Unable to create resource from the given stream. Write to filesystem aborted.');
}

return $this->write($path, $resource);
return $this->write($path, $resource, $mimeType);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public function update($initialVersion) {
$this->setVersion('2.22.0');
}

$this->skip('2.22.0', '2.23.0');
$this->skip('2.22.0', '2.24.0');


}
Expand Down
113 changes: 1 addition & 112 deletions test/RestTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,10 @@

include_once dirname(__FILE__) . '/../includes/raw_start.php';

use \common_ext_ExtensionsManager;
use \common_persistence_Manager;


abstract class RestTestCase extends TaoPhpUnitTestRunner
abstract class RestTestCase extends RestTestRunner
{

protected $host = ROOT_URL;

protected $userUri = "";

protected $login = "";

protected $password = "";


public abstract function serviceProvider();




public function setUp()
{
TaoPhpUnitTestRunner::initTest();
$this->disableCache();

// creates a user using remote script from joel

$testUserData = array(
PROPERTY_USER_LOGIN => 'tjdoe',
PROPERTY_USER_PASSWORD => 'test123',
PROPERTY_USER_LASTNAME => 'Doe',
PROPERTY_USER_FIRSTNAME => 'John',
PROPERTY_USER_MAIL => '[email protected]',
PROPERTY_USER_DEFLG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(),
PROPERTY_USER_UILG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(),
PROPERTY_USER_ROLES => array(
INSTANCE_ROLE_GLOBALMANAGER
)
);

$testUserData[PROPERTY_USER_PASSWORD] = 'test' . rand();

$data = $testUserData;
$data[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($data[PROPERTY_USER_PASSWORD]);
$tmclass = new \core_kernel_classes_Class(CLASS_TAO_USER);
$user = $tmclass->createInstanceWithProperties($data);
\common_Logger::i('Created user ' . $user->getUri());

// prepare a lookup table of languages and values
$usage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
$propValue = new \core_kernel_classes_Property(RDF_VALUE);
$langService = \tao_models_classes_LanguageService::singleton();

$lookup = array();
foreach ($langService->getAvailableLanguagesByUsage($usage) as $lang) {
$lookup[$lang->getUri()] = (string) $lang->getUniquePropertyValue($propValue);
}

$data = array(
'rootUrl' => ROOT_URL,
'userUri' => $user->getUri(),
'userData' => $testUserData,
'lang' => $lookup
);

$this->login = $data['userData'][PROPERTY_USER_LOGIN];
$this->password = $data['userData'][PROPERTY_USER_PASSWORD];
$this->userUri = $data['userUri'];
}

public function tearDown()
{
// removes the created user
$user = new \core_kernel_classes_Resource($this->userUri);
$success = $user->delete();
$this->restoreCache();
}

/**
* shall be used beyond high level http connections unit tests (default parameters)
*
* @param
* returnType CURLINFO_HTTP_CODE, etc... (default returns rhe http response data
*
* @return mixed
*/
protected function curl($url, $method = CURLOPT_HTTPGET, $returnType = "data", $curlopt_httpheaders = array())
{
$process = curl_init($url);
if ($method != "DELETE") {
curl_setopt($process, $method, 1);
} else {
curl_setopt($process, CURLOPT_CUSTOMREQUEST, "DELETE");
}

curl_setopt($process, CURLOPT_USERPWD, $this->login . ":" . $this->password);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);

$headers = array_merge(array(
"Accept: application/json"
), $curlopt_httpheaders);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
if ($method == CURLOPT_POST) {
curl_setopt($process, CURLOPT_POSTFIELDS, "");
}
// curl_setopt($process,CURLOPT_HTTPHEADER,$curlopt_httpheaders);
$data = curl_exec($process);
if ($returnType != "data") {
$data = curl_getinfo($process, $returnType);
}
curl_close($process);
return $data;
}

/**
* @dataProvider serviceProvider
Expand Down
Loading

0 comments on commit adc0dc5

Please sign in to comment.