Commit: f9771dfe2f8c84bbdf6127ab3d6796a6dadf1b2f

Author: alkemann | Date: 2009-11-17 19:38:22 +0100
test for applying filter to `MockParse`
diff --git a/tests/cases/models/PasteTest.php b/tests/cases/models/PasteTest.php index b58e50c..49036c7 100644 --- a/tests/cases/models/PasteTest.php +++ b/tests/cases/models/PasteTest.php @@ -21,6 +21,13 @@ class MockPaste extends \app\models\Paste { return $this->_classes; } + public static function &mockParse(&$doc) { + if (!($doc instanceof \lithium\data\model\Document)) { + return null; + } + $doc->parsed = 'PARSED'; + return $doc; + } } @@ -169,6 +176,28 @@ class PasteTest extends \lithium\test\Unit { $this->assertEqual($expected, $result); } + public function testApplyingFilter() { + MockPaste::applyFilter('save', function($self, $params, $chain) { + $document = $params['record']; + if ($document->language != 'text' && + in_array($document->language, MockPaste::$languages)) { + $document = MockPaste::mockParse($document); + } + return $document ; + }); + + $data = array( + 'content' => 'echo $this->function("lol");', + 'author' => 'TomGood', + 'language' => 'php' + ); + $paste = MockPaste::create($data); + $result = $paste->save(); + + $expected = 'PARSED'; + $this->assertEqual($expected, $result->parsed); + } + } ?> \ No newline at end of file