public function addCustomVariable() { $dbTable = $this->getDbTableName(); $index = $this->getHighestCustomVarIndex() + 1; $maxLen = CustomVariables::getMaxLengthCustomVariables(); Db::exec(sprintf('ALTER TABLE %s ', $dbTable) . sprintf('ADD COLUMN custom_var_k%d VARCHAR(%d) DEFAULT NULL,', $index, $maxLen) . sprintf('ADD COLUMN custom_var_v%d VARCHAR(%d) DEFAULT NULL;', $index, $maxLen)); return $index; }
public static function truncateCustomVariable($input) { return substr(trim($input), 0, CustomVariables::getMaxLengthCustomVariables()); }
public function test_getCustomVariablesInPageScope_ShouldTruncateValuesIfTheyAreTooLong() { $maxLen = CustomVariables::getMaxLengthCustomVariables(); $customVars = $this->buildCustomVars(array('mykey' => 'myval', 'test' => str_pad('test', $maxLen + 5, 't'))); $expected = $this->buildExpectedCustomVars(array('mykey' => 'myval', 'test' => str_pad('test', $maxLen, 't'))); $this->assertCustomVariablesInPageScope($expected, $customVars); }
public function test_truncateCustomVariable_shouldActuallyTruncateTheValue() { $len = CustomVariables::getMaxLengthCustomVariables(); $input = str_pad('test', $len + 2, 't'); $this->assertGreaterThan(100, $len); $truncated = Request::truncateCustomVariable($input); $this->assertEquals(str_pad('test', $len, 't'), $truncated); }