コード例 #1
0
ファイル: RecordTest.php プロジェクト: Zunair/xataface
 /**
  * Links (ie: URLs) can be associated with fields of a table by defining a "link"
  * property for a field in the fields.ini file or by defining a fieldname__link()
  * method in the delegate class.  These links are accessible via the Table::getLink()
  * method which resolves any variables in the link provided and returns the link
  * in the same format as it is defined in its place of origin (either the fields.ini file
  * or the delegate class.
  *
  * Links can be in the form of a query array, or in the form of a string (which should
  * be a url).
  * In this test, `fname`, `lname`, and `description` fields have links defined in the 
  * Profiles delegate class.  
  */
 function test_links()
 {
     $profiles = new Dataface_Record('Profiles', array());
     // Part I:  Testing links produced by the delegate *__link() methods.
     //--------------------------------------------------------------------
     // First test a link with explicit values where the delegate method __link() is defined
     // and the delegate method explicitly returns an array.
     $profiles->setValues(array("fname" => "John", "lname" => "Thomas"));
     $link = $profiles->getLink("fname");
     $this->assertEquals($link["fname"], "John");
     $this->assertEquals($link["lname"], "Thomas");
     $this->assertEquals($link["description"], "My name is John");
     // Try the same thing where no link is defined
     $link = $profiles->getLink("id");
     $this->assertEquals($link, null);
     // Now test a link with implicit values where the delegate method __link() is defined
     // and the delegate method returns an array.
     $table = new Dataface_Record('Profiles', array());
     $table->clearValues();
     $table->setValues(array("fname" => "John", "lname" => "Thomas"));
     $link = $profiles->getLink("fname");
     $this->assertEquals($link["fname"], "John");
     $this->assertEquals($link["lname"], "Thomas");
     $this->assertEquals($link["description"], "My name is John");
     // Try same thing when no link is defined
     $link = $profiles->getLink("id");
     $this->assertEquals($link, null);
     //Now test the link returned by a field that returns the link as a string with no
     // variables that need parsing.
     $link = $profiles->getLink("lname");
     $this->assertEquals("http://www.google.ca?fname=John&lname=Thomas", $link);
     // Now test the link returned by a field that returns a link that contains
     // variables (which should automatically be resolved by the getLink() method.
     // This tests the delegate still.
     $link = $profiles->getLink("description");
     $this->assertEquals("http://www.google.ca?fname=John&lname=Thomas", $link);
     // Part II: Testing links defined in the fields.ini file
     //-------------------------------------------------------------------------
     // Test a link with no variables requiring resolving
     $link = $profiles->getLink("dob");
     $this->assertEquals("http://www.google.ca", $link);
     // Test a link with variables that need to be resolved.
     $link = $profiles->getLink("phone1");
     $this->assertEquals("http://www.google.ca?fname=John", $link);
     $profiles->clearValues();
     $profiles->setValue("fname", "Thomas");
     $link = $profiles->getLink("phone1");
     $this->assertEquals("http://www.google.ca?fname=Thomas", $link);
 }
コード例 #2
0
ファイル: QueryBuilderTest.php プロジェクト: Zunair/xataface
 function test_query_builder_update_snapshot()
 {
     $builder = new Dataface_QueryBuilder('Profiles');
     // test default update functionality.
     $s = new Dataface_Record('Profiles', array());
     $s->clearValues();
     $s->setValues(array('id' => 10, 'fname' => 'John', 'lname' => 'Smith', 'title' => 'President Financial Accounting', 'phone1' => '555-555-5555', 'description' => 'This is a description', 'favtime' => '14:23:56', 'dob' => '1978-12-27', 'datecreated' => '19991224060708', 'lastlogin' => '1978-12-27 14:45:23'));
     $s->setSnapshot();
     $s->setValues(array('id' => 50, 'fname' => 'Susan', 'lname' => 'Moore', 'phone1' => '555-555-5556', 'description' => 'This is another description', 'favtime' => '14:23:57', 'dob' => '1978-12-28', 'datecreated' => '19991224060709', 'lastlogin' => '1978-12-28 14:45:24'));
     $this->assertEquals($builder->update($s), "UPDATE `Profiles` SET `id` = '50', `fname` = 'Susan', `lname` = 'Moore', `description` = 'This is another description', `dob` = '1978-12-28', `phone1` = '555-555-5556', `datecreated` = '19991224060709', `favtime` = '14:23:57', `lastlogin` = '1978-12-28 14:45:24' WHERE `Profiles`.`id` = '10' LIMIT 1");
 }