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
0
 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);
 }
 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);
 }
 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);
 }