<?php
namespace Jaxon\Tests\CallableClass\Request;
use Jaxon\Jaxon;
use PHPUnit\Framework\TestCase;
/**
* @covers Jaxon\Request
*/
final class RequestTest extends TestCase
{
public static function setUpBeforeClass()
{
include __DIR__ . '/defs/classes.php';
jaxon()->register(Jaxon::CALLABLE_OBJECT, 'Sample');
}
public function testRequestToJaxonClass()
{
$this->assertEquals(
"JaxonSample.method()",
rq('Sample')->call('method')->getScript()
);
}
public function testRequestToJaxonClassWithParameter()
{
$this->assertEquals(
"JaxonSample.method('string', 2, true)",
rq('Sample')->call('method', 'string', 2, true)->getScript()
);
}
public function testRequestToJaxonClassWithFormParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.getFormValues('elt_id'))",
rq('Sample')->call('method', pr()->form('elt_id'))->getScript()
);
}
public function testRequestToJaxonClassWithInputParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.$('elt_id').value)",
rq('Sample')->call('method', pr()->input('elt_id'))->getScript()
);
}
public function testRequestToJaxonClassWithCheckedParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.$('check_id').checked)",
rq('Sample')->call('method', pr()->checked('check_id'))->getScript()
);
}
public function testRequestToJaxonClassWithSelectParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.$('select_id').value)",
rq('Sample')->call('method', pr()->select('select_id'))->getScript()
);
}
public function testRequestToJaxonClassWithInnerHTMLParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.$('elt_id').innerHTML)",
rq('Sample')->call('method', pr()->html('elt_id'))->getScript()
);
}
public function testRequestToJaxonClassWithMultipleParameter()
{
$this->assertEquals(
"JaxonSample.method(jaxon.$('check_id').checked, jaxon.$('select_id').value, jaxon.$('elt_id').innerHTML)",
rq('Sample')->call('method', pr()->checked('check_id'), pr()->select('select_id'), pr()->html('elt_id'))->getScript()
);
}
public function testRequestToJaxonClassWithConfirmation()
{
$this->assertEquals(
"if(confirm('Really?')){JaxonSample.method(jaxon.$('elt_id').innerHTML);}",
rq('Sample')->call('method', pr()->html('elt_id'))->confirm("Really?")->getScript()
);
}
public function testRequestToJaxonClassWithConfirmationAndSubstitution()
{
$this->assertEquals(
"if(confirm('Really M. {1}?'.supplant({'1':jaxon.$('name_id').innerHTML}))){JaxonSample.method(jaxon.$('elt_id').innerHTML);}",
rq('Sample')->call('method', pr()->html('elt_id'))->confirm("Really M. {1}?", pr()->html('name_id'))->getScript()
);
}
public function testRequestToJaxonClassWithConditionWhen()
{
$this->assertEquals(
"if(jaxon.$('cond_id').checked){JaxonSample.method(jaxon.$('elt_id').innerHTML);}",
rq('Sample')->call('method', pr()->html('elt_id'))->when(pr()->checked('cond_id'))->getScript()
);
}
public function testRequestToJaxonClassWithConditionWhenAndMessage()
{
$this->assertEquals(
"if(jaxon.$('cond_id').checked){JaxonSample.method(jaxon.$('elt_id').innerHTML);}" .
"else{alert('Please check the option');}",
rq('Sample')->call('method', pr()->html('elt_id'))
->when(pr()->checked('cond_id'))
->elseShow("Please check the option")->getScript()
);
}
public function testRequestToJaxonClassWithConditionWhenAndMessageAndSubstitution()
{
$this->assertEquals(
"if(jaxon.$('cond_id').checked){JaxonSample.method(jaxon.$('elt_id').innerHTML);}else" .
"{alert('M. {1}, please check the option'.supplant({'1':jaxon.$('name_id').innerHTML}));}",
rq('Sample')->call('method', pr()->html('elt_id'))
->when(pr()->checked('cond_id'))
->elseShow("M. {1}, please check the option", pr()->html('name_id'))->getScript()
);
}
public function testRequestToJaxonClassWithConditionUnless()
{
$this->assertEquals(
"if(!(jaxon.$('cond_id').checked)){JaxonSample.method(jaxon.$('elt_id').innerHTML);}",
rq('Sample')->call('method', pr()->html('elt_id'))
->unless(pr()->checked('cond_id'))->getScript()
);
}
public function testRequestToJaxonClassWithConditionUnlessAndMessage()
{
$this->assertEquals(
"if(!(jaxon.$('cond_id').checked)){JaxonSample.method(jaxon.$('elt_id').innerHTML);}" .
"else{alert('Please uncheck the option');}",
rq('Sample')->call('method', pr()->html('elt_id'))
->unless(pr()->checked('cond_id'))
->elseShow("Please uncheck the option")->getScript()
);
}
public function testRequestToJaxonClassWithConditionUnlessAndMessageAndSubstitution()
{
$this->assertEquals(
"if(!(jaxon.$('cond_id').checked)){JaxonSample.method(jaxon.$('elt_id').innerHTML);}" .
"else{alert('M. {1}, please uncheck the option'.supplant({'1':jaxon.$('name_id').innerHTML}));}",
rq('Sample')->call('method', pr()->html('elt_id'))
->unless(pr()->checked('cond_id'))
->elseShow("M. {1}, please uncheck the option", pr()->html('name_id'))->getScript()
);
}
}
|