示例#1
1
 public function testFilterZendFilterAsArray()
 {
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false);
     $inputFilter = new Input($objectManagerMock);
     /** This filter should be applied to 'field1' field value only */
     $inputFilter->setFilters(array('field1' => array(array('zend' => 'StringToUpper', 'args' => array('encoding' => 'utf-8')))));
     /** Execute SUT and ensure that array items were filtered correctly */
     $inputArray = ['field1' => 'value1', 'field2' => 'value2'];
     $expectedOutput = ['field1' => 'VALUE1', 'field2' => 'value2'];
     $this->assertEquals($expectedOutput, $inputFilter->filter($inputArray), 'Array was filtered incorrectly.');
 }
示例#2
0
 public function test_filter()
 {
     $_GET = array('foo' => 'foo', 'zstring' => "foobar", 'znull' => "", 'zint' => '42' . "" . '42', 'zintbaz' => "baz42");
     $_POST = $_GET;
     $_REQUEST = $_GET;
     $INPUT = new Input();
     $filter = array($this, 'myfilter');
     $this->assertNotSame('foobar', $INPUT->str('zstring'));
     $this->assertSame('foobar', $INPUT->filter()->str('zstring'));
     $this->assertSame('bar', $INPUT->filter($filter)->str('foo'));
     $this->assertSame('bar', $INPUT->filter()->str('znull', 'bar', true));
     $this->assertNotSame('foobar', $INPUT->str('zstring'));
     // make sure original input is unmodified
     $this->assertNotSame('foobar', $INPUT->get->str('zstring'));
     $this->assertSame('foobar', $INPUT->get->filter()->str('zstring'));
     $this->assertSame('bar', $INPUT->get->filter($filter)->str('foo'));
     $this->assertSame('bar', $INPUT->get->filter()->str('znull', 'bar', true));
     $this->assertNotSame('foobar', $INPUT->get->str('zstring'));
     // make sure original input is unmodified
     $this->assertNotSame(4242, $INPUT->int('zint'));
     $this->assertSame(4242, $INPUT->filter()->int('zint'));
     $this->assertSame(42, $INPUT->filter($filter)->int('zintbaz'));
     $this->assertSame(42, $INPUT->filter()->str('znull', 42, true));
     $this->assertSame(true, $INPUT->bool('znull'));
     $this->assertSame(false, $INPUT->filter()->bool('znull'));
     $this->assertSame('foobar', $INPUT->filter()->valid('zstring', array('foobar', 'bang')));
 }
示例#3
0
 /**
  * ฟังก์ชั่นส่งอีเมล์ลืมรหัสผ่าน
  */
 public function forgot()
 {
     // ค่าที่ส่งมา
     $save = \Input::filter($_POST);
     // query user
     $sql = "SELECT `id`,`email`,`activatecode` FROM `" . $this->tableWithPrefix('user') . "` WHERE (`email`=:email OR `phone1`=:email) AND `fb`='0' LIMIT 1";
     $where = array(':email' => $save['email']);
     $user = $this->db->customQuery($sql, true, $where);
     if (empty($user)) {
         self::$login_message = Language::get('not a registered user');
         self::$login_input = 'email_email';
         self::$text_email = $save['email'];
     } else {
         $user = $user[0];
         // สุ่มรหัสผ่านใหม่
         $password = \Text::rndname(6);
         // ส่งเมล์แจ้งสมาชิก
         $replace = array();
         $replace['/%PASSWORD%/'] = $password;
         $replace['/%EMAIL%/'] = $user['email'];
         if (empty($user['activatecode'])) {
             // send mail
             $err = \Email::send(3, 'member', $replace, $user['email']);
         } else {
             $replace['/%ID%/'] = $user['activatecode'];
             // send mail
             $err = \Email::send(1, 'member', $replace, $user['email']);
         }
         if (empty($err)) {
             // อัปเดทรหัสผ่านใหม่
             $save_password = md5($password . $user['email']);
             $this->db->update($this->tableWithPrefix('user'), $user['id'], array('password' => $save_password));
             // สำเร็จ
             self::$login_message = Language::get('Your message was sent successfully');
             // ไปหน้า login
             $_REQUEST['action'] = 'login';
         } else {
             // ไม่สามารถส่งอีเมล์ได้
             self::$login_message = $err;
             self::$login_input = 'email_email';
         }
         self::$text_email = $user['email'];
     }
     return $this;
 }