本文整理汇总了PHP中InsightMySQLDAO::insertInsight方法的典型用法代码示例。如果您正苦于以下问题:PHP InsightMySQLDAO::insertInsight方法的具体用法?PHP InsightMySQLDAO::insertInsight怎么用?PHP InsightMySQLDAO::insertInsight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InsightMySQLDAO
的用法示例。
在下文中一共展示了InsightMySQLDAO::insertInsight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertInsight
public function testInsertInsight()
{
$dao = new InsightMySQLDAO();
$insight = new Insight();
$e = null;
//test exception when fields are not set
try {
$result = $dao->insertInsight($insight);
} catch (InsightFieldNotSetException $e) {
//do assertions outside of the catch block to make sure they run every time
}
$this->assertNotNull($e);
$this->assertEqual($e->getMessage(), 'Insight instance_id is not set.');
$e = null;
$insight->instance_id = 1;
$insight->slug = 'avg_replies_per_week';
$insight->date = '2012-05-05';
$insight->headline = 'Oh hai!';
$insight->text = "You rock";
$insight->emphasis = Insight::EMPHASIS_MED;
$insight->filename = "test_filename";
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->headline, 'Oh hai!');
$this->assertEqual($result->text, 'You rock');
$this->assertEqual($result->filename, 'test_filename');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
//inserting existing insight should update
$insight->headline = "Ohai updated headline";
$insight->text = 'Updated: You rock';
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->headline, 'Ohai updated headline');
$this->assertEqual($result->text, 'Updated: You rock');
//Filename shouldn't change on update
$this->assertEqual($result->filename, 'test_filename');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
}
示例2: testInsertInsight
public function testInsertInsight()
{
$dao = new InsightMySQLDAO();
//date specified
$result = $dao->insertInsight($slug = 'avg_replies_per_week', $instance_id = 1, $date = '2012-05-05', $prefix = 'Oh hai!', $text = 'You rock', $filename = "test_insight");
$this->assertTrue($result);
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->prefix, 'Oh hai!');
$this->assertEqual($result->text, 'You rock');
$this->assertEqual($result->filename, 'test_insight');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_LOW);
//inserting existing insight should update
$result = $dao->insertInsight('avg_replies_per_week', 1, '2012-05-05', 'Ohai!', 'Updated: You rock', 'tester_insight', Insight::EMPHASIS_HIGH);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->prefix, 'Ohai!');
$this->assertEqual($result->text, 'Updated: You rock');
//Filename shouldn't change on update
$this->assertEqual($result->filename, 'test_insight');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_HIGH);
}
示例3: testInsertInsight
public function testInsertInsight()
{
$dao = new InsightMySQLDAO();
$insight = new Insight();
$e = null;
//test exception when fields are not set
try {
$result = $dao->insertInsight($insight);
} catch (InsightFieldNotSetException $e) {
//do assertions outside of the catch block to make sure they run every time
}
$this->assertNotNull($e);
$this->assertEqual($e->getMessage(), 'Insight instance_id is not set.');
$e = null;
//Test insight without related data
$insight->instance_id = 1;
$insight->slug = 'avg_replies_per_week';
$insight->date = '2012-05-05';
$insight->headline = 'Oh hai!';
$insight->text = "You rock";
$insight->emphasis = Insight::EMPHASIS_MED;
$insight->filename = "test_filename";
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->headline, 'Oh hai!');
$this->assertEqual($result->text, 'You rock');
$this->assertEqual($result->filename, 'test_filename');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
$this->assertEqual($result->header_image, null);
//inserting existing insight should update
$insight->headline = "Ohai updated headline";
$insight->text = 'Updated: You rock';
$insight->header_image = 'my_image.png';
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->debug(Utils::varDumpToString($result));
$this->assertEqual($result->headline, 'Ohai updated headline');
$this->assertEqual($result->text, 'Updated: You rock');
$this->assertEqual($result->header_image, 'my_image.png');
//Filename and emphasis shouldn't change on update
$this->assertEqual($result->filename, 'test_filename');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
//Test insight with related data
$insight->instance_id = 1;
$insight->slug = 'avg_replies_per_week';
$insight->date = '2012-05-06';
$insight->headline = 'Oh hai!';
$insight->text = "You rock";
$insight->emphasis = Insight::EMPHASIS_MED;
$insight->filename = "test_filename";
$insight->related_data = array('favorite_color' => 'blue', 'favorite_fruit' => 'bananas');
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-06');
$related_data = unserialize($result->related_data);
$this->assertIsA($related_data, 'array');
$this->assertEqual($related_data['favorite_color'], 'blue');
//inserting existing insight should update
$insight->headline = "Ohai updated headline";
$insight->text = 'Updated: You rock';
$insight->related_data = array('favorite_color' => 'purple', 'favorite_fruit' => 'Apple');
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-06');
$this->assertEqual($result->headline, 'Ohai updated headline');
$this->assertEqual($result->text, 'Updated: You rock');
$related_data = unserialize($result->related_data);
$this->assertEqual($related_data['favorite_color'], 'purple');
//Filename shouldn't change on update
$this->assertEqual($result->filename, 'test_filename');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
//test too-long related data
$i = 1;
//generate related data that's exactly 1 char longer than the field can handle when serialized
$data_length = 65535 + 1 - 16;
// serializing this particular data adds 16 chars
while ($i <= $data_length) {
if ($i != $data_length) {
$insight->related_data .= "-";
} else {
// for debugging purposes, the last char of this related_data will be different than the rest
$insight->related_data .= "a";
}
$i++;
}
$this->debug($insight->related_data);
$this->debug('Pre-insert length: ' . strlen($insight->related_data));
$serialized_related_data = serialize($insight->related_data);
$this->debug('Pre-insert serialized length: ' . strlen($serialized_related_data));
$this->expectException('InsightFieldExceedsMaxLengthException');
$result = $dao->insertInsight($insight);
//$retrieved_insight = $dao->getInsight('avg_replies_per_week', 1, '2012-05-06');
//$this->debug(Utils::varDumpToString($retrieved_insight));
//$this->debug('Post-insert length: '.strlen($retrieved_insight->related_data));
//$this->debug($retrieved_insight->related_data);
//.........这里部分代码省略.........
示例4: testInsertInsight
public function testInsertInsight()
{
$dao = new InsightMySQLDAO();
//date specified
$result = $dao->insertInsight('avg_replies_per_week', 1, '2012-05-05', 'Oh hai!', 'You rock');
$this->assertTrue($result);
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->prefix, 'Oh hai!');
$this->assertEqual($result->text, 'You rock');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_LOW);
//inserting existing insight should update
$result = $dao->insertInsight('avg_replies_per_week', 1, '2012-05-05', 'Ohai!', 'Updated: You rock', Insight::EMPHASIS_HIGH);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
$this->assertEqual($result->prefix, 'Ohai!');
$this->assertEqual($result->text, 'Updated: You rock');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_HIGH);
}