Commit b7a818b0 authored by Nicolas Tostin's avatar Nicolas Tostin Committed by Youri van Koppen
Browse files

Issue #3170553 by tostinni, MegaChriz, jamesdixon, jrochate, NWOM: Allow...

Issue #3170553 by tostinni, MegaChriz, jamesdixon, jrochate, NWOM: Allow numeric to be tampered in FindReplace & sprintf functions.
parent 9886834f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -96,8 +96,8 @@ class FindReplace extends TamperBase {
   * {@inheritdoc}
   */
  public function tamper($data, TamperableItemInterface $item = NULL) {
    if (!is_string($data)) {
      throw new TamperException('Input should be a string.');
    if (!is_string($data) && !is_numeric($data)) {
      throw new TamperException('Input should be a string or numeric.');
    }

    $function = $this->getFunction();
+2 −2
Original line number Diff line number Diff line
@@ -90,8 +90,8 @@ class FindReplaceRegex extends TamperBase {
   * {@inheritdoc}
   */
  public function tamper($data, TamperableItemInterface $item = NULL) {
    if (!is_string($data)) {
      throw new TamperException('Input should be a string.');
    if (!is_string($data) && !is_numeric($data)) {
      throw new TamperException('Input should be a string or numeric.');
    }
    $find = $this->getSetting(self::SETTING_FIND);
    $replace = $this->getSetting(self::SETTING_REPLACE);
+2 −2
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ class Sprintf extends TamperBase {
   * {@inheritdoc}
   */
  public function tamper($data, TamperableItemInterface $item = NULL) {
    if (!is_string($data)) {
      throw new TamperException('Input should be a string.');
    if (!is_string($data) && !is_numeric($data)) {
      throw new TamperException('Input should be a string or numeric.');
    }
    return sprintf($this->getSetting(self::SETTING_TEXT_FORMAT), $data);
  }
+2 −2
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ class StrPad extends TamperBase {
   * {@inheritdoc}
   */
  public function tamper($data, TamperableItemInterface $item = NULL) {
    if (!is_string($data)) {
      throw new TamperException('Input should be a string.');
    if (!is_string($data) && !is_numeric($data)) {
      throw new TamperException('Input should be a string or numeric.');
    }

    return str_pad($data, $this->getSetting(self::SETTING_PAD_LENGTH), $this->getSetting(self::SETTING_PAD_STRING), $this->getSetting(self::SETTING_PAD_TYPE));
+14 −0
Original line number Diff line number Diff line
@@ -45,6 +45,20 @@ class FindReplaceRegexTest extends TamperPluginTestBase {
    $this->assertEquals('The dog went to the park.', $plugin->tamper('The Cat went to the park.'));
  }

  /**
   * Test the plugin with a single numeric value.
   */
  public function testNumericValue() {
    $config = [
      FindReplaceRegex::SETTING_FIND => '/5/',
      FindReplaceRegex::SETTING_REPLACE => '8',
      FindReplaceRegex::SETTING_LIMIT => '',
    ];
    $plugin = new FindReplaceRegex($config, 'find_replace_regex', [], $this->getMockSourceDefinition());
    $this->assertEquals('8', $plugin->tamper(5));
    $this->assertEquals('7', $plugin->tamper(7));
  }

  /**
   * Test the plugin as respecting word boundaries.
   */
Loading