diff --git a/api/src/Etemplate/Widget/test/TextboxTest.php b/api/src/Etemplate/Widget/test/TextboxTest.php new file mode 100644 index 0000000000..eea83987a7 --- /dev/null +++ b/api/src/Etemplate/Widget/test/TextboxTest.php @@ -0,0 +1,120 @@ +read(static::TEST_TEMPLATE, 'test'); + + // Exec + $content = array( + 'widget' => '', + 'widget_readonly' => '' + ); + $result = $this->mockedRoundTrip($etemplate, $content, array(), array()); + + // Check + $this->assertEquals(array('widget' => ''), $result); + + $content = array( + 'widget' => 'Hello', + 'widget_readonly' => 'World' + ); + $result = $this->mockedRoundTrip($etemplate, $content, array(), array()); + + // Check only the editable widget gives a value + $this->assertEquals(array('widget' => 'Hello'), $result); + } + + /** + * Test that the widget does not return a value if readonly + */ + public function testReadonly() + { + // Instanciate the template + $etemplate = new Etemplate(); + $etemplate->read(static::TEST_TEMPLATE, 'test'); + + // Exec + $content = array( + 'widget' => 'Hello', + 'widget_readonly' => 'World' + ); + $result = $this->mockedRoundTrip($etemplate, $content, array(), array('widget' => true)); + + // Check + $this->assertEquals(array(), $result); + } + + /** + * Test that an edited read-only widget does not return a value, even if the + * client side gives one, which should be an unusual occurrence. + */ + public function testEditedReadonly() + { + // Instanciate the template + $etemplate = new Etemplate(); + $etemplate->read(static::TEST_TEMPLATE, 'test'); + + // Exec + $content = array( + 'widget' => 'Hello', + 'widget_readonly' => 'World' + ); + $result = $this->mockedExec($etemplate, $content, array(), array('widget' => true), array()); + + // Check for the load + $data = array(); + foreach($result as $command) + { + if($command['type'] == 'et2_load') + { + $data = $command['data']; + break; + } + } + + // 'Edit' the data client side + $data['data']['content'] = array( + 'widget' => 'Goodnight', + 'widget_readonly' => 'Moon' + ); + + Etemplate::ajax_process_content($data['data']['etemplate_exec_id'], $data['data']['content'], false); + + $content = static::$mocked_exec_result; + static::$mocked_exec_result = array(); + + $this->assertEquals(array(), $content); + } +} diff --git a/api/templates/test/textbox_test.xet b/api/templates/test/textbox_test.xet new file mode 100644 index 0000000000..9dc327fb9c --- /dev/null +++ b/api/templates/test/textbox_test.xet @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file