コード例 #1
0
 public function testUpdateOptionByName()
 {
     // add one option
     $optiondao = new OptionMySQLDAO();
     // no options to update
     $this->assertEqual(0, $optiondao->updateOptionbyName('nonamespace', 'noname', 'value'));
     $builder1 = FixtureBuilder::build(self::TEST_TABLE, array('namespace' => 'test', 'option_name' => 'testname'));
     $builder2 = FixtureBuilder::build(self::TEST_TABLE, array('namespace' => 'test2', 'option_name' => 'testname2'));
     $this->assertEqual(1, $optiondao->updateOptionByName('test', 'testname', 'test_value123'));
     $sql = "select * from " . $this->table_prefix . 'options where option_id = ' . $builder1->columns['last_insert_id'];
     $stmt = PluginOptionMySQLDAO::$PDO->query($sql);
     $data = $stmt->fetch(PDO::FETCH_ASSOC);
     $this->assertEqual($data['option_name'], 'testname');
     $this->assertEqual($data['namespace'], 'test');
     $this->assertEqual($data['option_value'], 'test_value123');
     # we'll add or subtract a few seconds from/to the date to account for any lag...
     # date created is still 2 days old
     $this->assertTrue(strtotime($data['created']) < time() - 24 * 60 * 60 * 2 + 10);
     # last updated is now
     $this->assertTrue(strtotime($data['last_updated']) > time() - 10);
 }