Skip to content

Commit

Permalink
Merge pull request #19 from m0hamed/change_state
Browse files Browse the repository at this point in the history
refactoring and validations
  • Loading branch information
ruleant committed Sep 19, 2013
2 parents ec72140 + faaadc6 commit 3173afe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 28 deletions.
52 changes: 35 additions & 17 deletions app/Model/Incident.php
Expand Up @@ -64,6 +64,22 @@ class Incident extends AppModel {
'rule' => 'notEmpty',
'required' => true,
),
'user_os' => array(
'rule' => 'notEmpty',
'required' => true,
),
'script_name' => array(
'rule' => 'notEmpty',
'required' => true,
),
'server_software' => array(
'rule' => 'notEmpty',
'required' => true,
),
'configuration_storage' => array(
'rule' => 'notEmpty',
'required' => true,
),
);

/**
Expand Down Expand Up @@ -218,12 +234,12 @@ protected function _getSchematizedIncident($bugReport) {
$bugReport = Sanitize::clean($bugReport);
$schematizedReport = array(
'pma_version' => $bugReport['pma_version'],
'php_version' => $this->_getSimplePhpVersion($bugReport['php_version']),
'php_version' => $this->_getSimpleVersion($bugReport['php_version'], 2),
'steps' => $bugReport['steps'],
'error_message' => $bugReport['exception']['message'],
'error_name' => $bugReport['exception']['name'],
'browser' => $bugReport['browser_name'] . " "
. $this->_getMajorVersion($bugReport['browser_version']),
. $this->_getSimpleVersion($bugReport['browser_version'], 1),
'user_os' => $bugReport['user_os'],
'script_name' => $bugReport['script_name'],
'configuration_storage' => $bugReport['configuration_storage'],
Expand Down Expand Up @@ -275,26 +291,28 @@ protected function _getIdentifyingLocation($stacktrace) {
return $fallback;
}

/**
* Gets the major version number of a version string
*
* @param String $fullVersion the version string
* @return String the major version part
*/
protected function _getMajorVersion($fullVersion) {
preg_match("/^\d+/", $fullVersion, $matches);
$simpleVersion = $matches[0];
return $simpleVersion;
}

/**
* Gets the major and minor version number of a version string
* Gets a part of a version string according to the specified version Length
*
* @param String $phpVersion the version string
* @param String $phpVersion the version string
* @param String $versionLength the number of version components to return. eg
* 1 for major version only and 2 for major and
* minor version
* @return String the major and minor version part
*/
protected function _getSimplePhpVersion($phpVersion) {
preg_match("/^\d+\.\d+/", $phpVersion, $matches);
protected function _getSimpleVersion($versionString, $versionLength) {
$versionLength = (int) $versionLength;
if ($versionLength < 1) {
$versionLength = 1;
}
/* modify the re to accept a variable number of version components. I
* atleast take one component and optionally get more components if need be.
* previous code makes sure that the $versionLength variable is a positive
* int
*/
preg_match("/^(\d+\.){" . ($versionLength - 1) . "}\d+/", $versionString,
$matches);
$simpleVersion = $matches[0];
return $simpleVersion;
}
Expand Down
29 changes: 18 additions & 11 deletions app/Test/Case/Model/IncidentTest.php
Expand Up @@ -4,7 +4,7 @@
App::uses('Incident', 'Model');

class IncidentTest extends CakeTestCase {

public function setUp() {
parent::setUp();
$this->Incident = ClassRegistry::init('Incident');
Expand Down Expand Up @@ -91,22 +91,29 @@ public function testGetServer() {
$this->assertEquals("UNKNOWN", $result);
}

public function testGetSimplePhpVersion() {
$method = new ReflectionMethod('Incident', '_getSimplePhpVersion');
public function testGetSimpleVersion() {
$method = new ReflectionMethod('Incident', '_getSimpleVersion');
$method->setAccessible(true);

$result = $method->invoke($this->Incident,
"5.3.2.17");
$this->assertEquals("5.3", $result);
}
"15.3.12.17", 1);
$this->assertEquals("15", $result);

public function testGetMajorVersion() {
$method = new ReflectionMethod('Incident', '_getMajorVersion');
$method->setAccessible(true);
$result = $method->invoke($this->Incident,
"15.3.12.17", 2);
$this->assertEquals("15.3", $result);

$result = $method->invoke($this->Incident,
"15.3.12.17", 3);
$this->assertEquals("15.3.12", $result);

$result = $method->invoke($this->Incident,
"15.3.12.17", "wrong argument");
$this->assertEquals("15", $result);

$result = $method->invoke($this->Incident,
"23.3.2.17");
$this->assertEquals("23", $result);
"15.3.12.17", -1);
$this->assertEquals("15", $result);
}

public function testGetIdentifyingLocation() {
Expand Down

0 comments on commit 3173afe

Please sign in to comment.