/** * testCommentAdd * * @return void * @access public */ public function testCommentAdd() { //No data $expected = null; $this->assertEqual($expected, $this->Model->commentAdd(0)); //Empty Data $expected = false; $this->assertEqual($expected, $this->Model->commentAdd(0, array())); try { $this->Model->commentAdd(1); $this->fail(); } catch (BlackHoleException $e) { $this->pass(); } // If it's successfull, commentAdd returns the id of the newly created comment $options = array('userId' => '47ea303a-3b2c-4251-b313-4816c0a800fa', 'modelId' => '1', 'modelName' => 'Article', 'defaultTitle' => 'Specified default title', 'data' => array('body' => "Comment Test successful Captn!", 'title' => 'Not the Default title'), 'permalink' => 'http://testing.something.com'); $result = $this->Model->commentAdd(0, $options); $this->assertFalse(empty($result)); $this->assertTrue(is_string($result)); $this->Model->Comment->id = $result; $this->assertEqual($this->Model->Comment->field('title'), $options['defaultTitle']); $this->Model->id = $options['modelId']; $oldCount = $this->Model->field('comments'); $this->assertTrue(is_numeric($oldCount)); // Testing adding a comment (approved by default) $options['data'] = array('Comment' => $options['data']); $result = $this->Model->commentAdd(0, $options); $this->assertTrue(is_string($result)); $this->Model->Comment->id = $result; $this->assertEqual($this->Model->Comment->field('title'), $options['data']['Comment']['title']); $this->assertEqual($this->Model->field('comments'), ++$oldCount); // Test adding non approved comment $options['data']['Comment']['approved'] = 0; $result = $this->Model->commentAdd(0, $options); $this->assertTrue(is_string($result)); $this->Model->id = $options['modelId']; $this->assertEqual($this->Model->field('comments'), $oldCount); // Test adding spam comment $options['data'] = array_merge($options['data'], array('Other' => array('title' => 'Free p0rn spam!'))); $this->assertFalse($this->Model->commentAdd(0, $options)); }
/** * testBeforeAndAfterCallbacks * * @return void */ public function testBeforeAndAfterCallbacks() { $this->Model = Classregistry::init('Article2'); $options = array('userId' => '47ea303a-3b2c-4251-b313-4816c0a800fa', 'modelId' => '1', 'modelName' => 'Article', 'defaultTitle' => 'Specified default title', 'data' => array('Comment' => array('body' => "Comment Test successful Captn!", 'title' => 'Not the Default title')), 'permalink' => 'http://testing.something.com'); $this->Model->commentAdd(0, $options); $this->assertEqual($this->Model->callbackData['beforeComment']['Comment']['title'], 'Changed in beforeComment!'); $this->assertEqual($this->Model->callbackData['afterComment']['Comment']['body'], 'Changed in afterComment!'); }
/** * testBeforeAndAfterCallbacks * * @return void */ public function testBeforeAndAfterCallbacks() { $listener = new CommentEventListener(); CakeEventManager::instance()->attach($listener); $this->Model = Classregistry::init('Article'); $options = array('userId' => '47ea303a-3b2c-4251-b313-4816c0a800fa', 'modelId' => '1', 'modelName' => 'Article', 'defaultTitle' => 'Specified default title', 'data' => array('Comment' => array('body' => "Comment Test successful Captn!", 'title' => 'Not the Default title')), 'permalink' => 'http://testing.something.com'); $this->Model->commentAdd(0, $options); $commentId = $this->Model->Comment->id; $comment = $this->Model->Comment->read(null, $commentId); $this->assertEqual($comment['Comment']['title'], 'Changed in beforeComment!'); $this->assertEqual($comment['Comment']['body'], 'Changed in afterComment!'); }