|
|
@@ -2542,6 +2542,103 @@ XML;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test updating params in a psr7 fashion.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testWithParam()
|
|
|
+ {
|
|
|
+ $request = new Request([
|
|
|
+ 'params' => ['controller' => 'Articles']
|
|
|
+ ]);
|
|
|
+ $result = $request->withParam('action', 'view');
|
|
|
+ $this->assertNotSame($result, $request, 'New instance should be made');
|
|
|
+ $this->assertFalse($request->param('action'), 'No side-effect on original');
|
|
|
+ $this->assertSame('view', $result->param('action'));
|
|
|
+
|
|
|
+ $result = $request->withParam('action', 'index')
|
|
|
+ ->withParam('plugin', 'DebugKit')
|
|
|
+ ->withParam('prefix', 'Admin');
|
|
|
+ $this->assertNotSame($result, $request, 'New instance should be made');
|
|
|
+ $this->assertFalse($request->param('action'), 'No side-effect on original');
|
|
|
+ $this->assertSame('index', $result->param('action'));
|
|
|
+ $this->assertSame('DebugKit', $result->param('plugin'));
|
|
|
+ $this->assertSame('Admin', $result->param('prefix'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test updating POST data in a psr7 fashion.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testWithData()
|
|
|
+ {
|
|
|
+ $request = new Request([
|
|
|
+ 'post' => [
|
|
|
+ 'Model' => [
|
|
|
+ 'field' => 'value'
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $result = $request->withData('Model.new_value', 'new value');
|
|
|
+ $this->assertNull($request->data('Model.new_value'), 'Original request should not change.');
|
|
|
+ $this->assertNotSame($result, $request);
|
|
|
+ $this->assertEquals('new value', $result->data('Model.new_value'));
|
|
|
+ $this->assertEquals('new value', $result->data['Model']['new_value']);
|
|
|
+ $this->assertEquals('value', $result->data('Model.field'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test updating POST data when keys don't exist
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testWithDataMissingIntermediaryKeys()
|
|
|
+ {
|
|
|
+ $request = new Request([
|
|
|
+ 'post' => [
|
|
|
+ 'Model' => [
|
|
|
+ 'field' => 'value'
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $result = $request->withData('Model.field.new_value', 'new value');
|
|
|
+ $this->assertEquals(
|
|
|
+ 'new value',
|
|
|
+ $result->data('Model.field.new_value')
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ 'new value',
|
|
|
+ $result->data['Model']['field']['new_value']
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test updating POST data with falsey values
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testWithDataFalseyValues()
|
|
|
+ {
|
|
|
+ $request = new Request([
|
|
|
+ 'post' => []
|
|
|
+ ]);
|
|
|
+ $result = $request->withData('false', false)
|
|
|
+ ->withData('null', null)
|
|
|
+ ->withData('empty_string', '')
|
|
|
+ ->withData('zero', 0)
|
|
|
+ ->withData('zero_string', '0');
|
|
|
+ $expected = [
|
|
|
+ 'false' => false,
|
|
|
+ 'null' => null,
|
|
|
+ 'empty_string' => '',
|
|
|
+ 'zero' => 0,
|
|
|
+ 'zero_string' => '0'
|
|
|
+ ];
|
|
|
+ $this->assertSame($expected, $result->data());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* loadEnvironment method
|
|
|
*
|
|
|
* @param array $env
|