Browse Source

Merge pull request #11884 from sohelrana820/master

Write some validation method and replaced deprecated method with new one!
Mark Story 8 years ago
parent
commit
8623e482df
2 changed files with 46 additions and 3 deletions
  1. 43 0
      tests/TestCase/Http/Client/FormDataTest.php
  2. 3 3
      tests/TestCase/Http/ClientTest.php

+ 43 - 0
tests/TestCase/Http/Client/FormDataTest.php

@@ -70,6 +70,27 @@ class FormDataTest extends TestCase
     }
 
     /**
+     * Test addMany method.
+     *
+     * @return void
+     */
+    public function testAddMany()
+    {
+        $data = new FormData();
+        $array = [
+            'key' => 'value',
+            'empty' => '',
+            'int' => '1',
+            'float' => '2.3'
+        ];
+        $data->addMany($array);
+        $this->assertCount(4, $data);
+        $result = (string)$data;
+        $expected = 'key=value&empty=&int=1&float=2.3';
+        $this->assertEquals($expected, $result);
+    }
+
+    /**
      * Test adding a part object.
      *
      * @return void
@@ -216,4 +237,26 @@ class FormDataTest extends TestCase
         ];
         $this->assertEquals(implode("\r\n", $expected), $result);
     }
+
+    /**
+     * Test contentType method.
+     *
+     * @return void
+     */
+    public function testContentType()
+    {
+        $data = new FormData();
+        $data->add('key', 'value');
+        $result = $data->contentType();
+        $expected = 'application/x-www-form-urlencoded';
+        $this->assertEquals($expected, $result);
+
+        $file = CORE_PATH . 'VERSION.txt';
+        $data = new FormData();
+        $data->addFile('upload', fopen($file, 'r'));
+        $boundary = $data->boundary();
+        $result = $data->contentType();
+        $expected = 'multipart/form-data; boundary="' . $boundary . '"';
+        $this->assertEquals($expected, $result);
+    }
 }

+ 3 - 3
tests/TestCase/Http/ClientTest.php

@@ -38,17 +38,17 @@ class ClientTest extends TestCase
             'host' => 'example.org',
         ];
         $http = new Client($config);
-        $result = $http->config();
+        $result = $http->getConfig();
         foreach ($config as $key => $val) {
             $this->assertEquals($val, $result[$key]);
         }
 
-        $result = $http->config([
+        $result = $http->setConfig([
             'auth' => ['username' => 'mark', 'password' => 'secret']
         ]);
         $this->assertSame($result, $http);
 
-        $result = $http->config();
+        $result = $http->getConfig();
         $expected = [
             'scheme' => 'http',
             'host' => 'example.org',