Browse Source

Adding tests for FlashComponent::__call

Refs #5825
Mark Story 11 years ago
parent
commit
d6b6e05e25
1 changed files with 32 additions and 0 deletions
  1. 32 0
      tests/TestCase/Controller/Component/FlashComponentTest.php

+ 32 - 0
tests/TestCase/Controller/Component/FlashComponentTest.php

@@ -147,4 +147,36 @@ class FlashComponentTest extends TestCase
         $result = $this->Session->read('Flash.flash');
         $this->assertEquals($expected, $result);
     }
+
+    /**
+     * Test magic call method.
+     *
+     * @covers \Cake\Controller\Component\FlashComponent::__call
+     * @return void
+     */
+    public function testCall()
+    {
+        $this->assertNull($this->Session->read('Flash.flash'));
+
+        $this->Flash->success('It worked');
+        $expected = [
+            'message' => 'It worked',
+            'key' => 'flash',
+            'element' => 'Flash/success',
+            'params' => []
+        ];
+        $result = $this->Session->read('Flash.flash');
+        $this->assertEquals($expected, $result);
+
+        $this->Flash->error('It did not work', ['element' => 'error_thing']);
+
+        $expected = [
+            'message' => 'It did not work',
+            'key' => 'flash',
+            'element' => 'Flash/error',
+            'params' => []
+        ];
+        $result = $this->Session->read('Flash.flash');
+        $this->assertEquals($expected, $result, 'Element is ignored in magic call.');
+    }
 }