Esempio n. 1
0
    function testProperties()
    {
        $dao = '<?xml version="1.0"?>
<dao xmlns="http://jelix.org/ns/dao/1.0">
  <datasources>
    <primarytable name="news" primarykey="news_id" />
    <foreigntable name="news_author" primarykey="author_id" onforeignkey="author_id" />
  </datasources>
</dao>';
        $parser = new testjDaoParser($this->_selector);
        $parser->testParseDatasource(simplexml_load_string($dao));
        foreach ($this->propDatas as $k => $t) {
            //$this->sendMessage("test good property ".$k);
            $xml = simplexml_load_string($t[0]);
            try {
                $p = new jDaoProperty($xml, $parser, $this->_tools);
                $this->assertComplexIdenticalStr($p, $t[1], "test {$k}");
            } catch (jDaoXmlException $e) {
                $this->fail("Exception sur le contenu xml inattendue : " . $e->getMessage() . ' (' . $e->getLocaleKey() . ')');
            } catch (Exception $e) {
                $this->fail("Exception inconnue : " . $e->getMessage());
            }
        }
    }
Esempio n. 2
0
    function testBadMethods()
    {
        $dao = '<?xml version="1.0"?>
<dao xmlns="http://jelix.org/ns/dao/1.0">
  <datasources>
    <primarytable name="news" primarykey="news_id" />
    <foreigntable name="news_author" primarykey="author_id" onforeignkey="author_id" />
  </datasources>
  <record>
    <property name="id" fieldname="news_id" datatype="autoincrement" />
    <property name="subject" datatype="string" />
    <property name="texte" datatype="string" />
    <property name="publishdate" datatype="date" />
    <property name="author_firstname" fieldname="firstname" datatype="string" table="news_author" />
    <property name="author_lastname" fieldname="lastname"  datatype="string" table="news_author" />
  </record>
</dao>';
        $parser = new testjDaoParser($this->_selector);
        $doc = simplexml_load_string($dao);
        $parser->testParseDatasource($doc);
        $parser->testParseRecord($doc, new mysqlDbTools(null));
        foreach ($this->badmethDatas as $k => $t) {
            //$this->sendMessage("test bad method ".$k);
            $xml = simplexml_load_string($t[0]);
            try {
                $p = new jDaoMethod($xml, $parser);
                $this->fail("Pas d'exception survenue !");
            } catch (jDaoXmlException $e) {
                $this->assertEqual($e->getLocaleKey(), $t[1]);
                $this->assertEqual($e->getLocaleParameters(), $t[2]);
            } catch (Exception $e) {
                $this->fail("Exception inconnue : " . $e->getMessage());
            }
        }
    }
    function testBadUpdateMethods2()
    {
        $dao = '<?xml version="1.0"?>
<dao xmlns="http://jelix.org/ns/dao/1.0">
  <datasources>
    <primarytable name="news" primarykey="news_id,foo_id" />
  </datasources>
  <record>
    <property name="id" fieldname="news_id" datatype="autoincrement" />
    <property name="id2" fieldname="foo_id" datatype="integer" />
  </record>
</dao>';
        $parser = new testjDaoParser($this->_selector);
        $xml = simplexml_load_string($dao);
        $tools = new mysqlDbTools(null);
        $parser->testParseDatasource($xml);
        $parser->testParseRecord($xml, $tools);
        //$this->sendMessage("test bad update method ");
        $xml = simplexml_load_string('<?xml version="1.0"?>
          <method name="tryupdate" type="update">
            <parameter name="something" />
            <values>
                <value property="foo_id" expr="$something" />
            </values>
          </method>');
        try {
            $p = new jDaoMethod($xml, $parser);
            $this->fail("Pas d'exception survenue !");
        } catch (jDaoXmlException $e) {
            $this->assertEqual($e->getLocaleKey(), 'jelix~daoxml.method.update.forbidden');
            $this->assertEqual($e->getLocaleParameters(), array('foo~bar', '', 'tryupdate'));
        } catch (Exception $e) {
            $this->fail("Exception inconnue : " . $e->getMessage());
        }
    }