Difference between revisions of "Basic Functions of a Wiki"

(/r/n, /r, & /n)
m (Notes)
Line 44: Line 44:
 
***** IP
 
***** IP
 
***** logged in
 
***** logged in
 
== Notes ==
 
* carriage return line feed issue
 
** linux uses LF only, mac uses CR only, win uses CRLF [http://www.websiterepairguy.com/articles/os/crlf.html]
 
** What do I do about this?
 
** What happens if we use CRLF ( chr(13).chr(10) )?
 
* whole page text, not just one section
 
* look for more duplication in code
 
 
=== getText ===
 
<code>
 
public function getText($locator)
 
{
 
return $this->selenium->getText($locator);
 
}
 
 
public function getText($locator)
 
{
 
return $this->getString("getText", array($locator));
 
}
 
 
private function getString($verb, $args = array())
 
{
 
try {
 
$result = $this->doCommand($verb, $args);
 
} catch (Testing_Selenium_Exception $e) {
 
return $e;
 
}
 
return substr($result, 3);
 
}
 
 
private function doCommand($verb, $args = array())
 
{
 
$url = sprintf('http://%s:%s/selenium-server/driver/?cmd=%s', $this->host, $this->port, urlencode($verb));
 
for ($i = 0; $i < count($args); $i++) {
 
$argNum = strval($i + 1);
 
$url .= sprintf('&%s=%s', $argNum, urlencode(trim($args[$i])));
 
}
 
if (isset($this->sessionId)) {
 
$url .= sprintf('&%s=%s', 'sessionId', $this->sessionId);
 
}
 
if ($this->driver == 'curl') {
 
$response = $this->useCurl($verb, $args, $url);
 
} else {
 
$response = $this->useNative($verb, $args, $url);
 
}
 
if (!preg_match('/^OK/', $response)) {
 
throw new Testing_Selenium_Exception('The Response of the Selenium RC is invalid: ' . $response);
 
}
 
return $response;
 
}</code>
 
==== useCurl ====
 
<code>
 
    private function useCurl($verb, $args, $url)
 
    {
 
        if (!function_exists('curl_init')) {
 
            throw new Testing_Selenium_Exception('cannot use curl exntensions. chosse or "native"');
 
        }
 
        if (!$ch = curl_init($url)) {
 
            throw new Testing_Selenium_Exception('Unable to setup curl');
 
        }
 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
        $result = curl_exec($ch);
 
        if (($errno = curl_errno($ch)) != 0) {
 
            echo("curl_errno: " . $errno);
 
            throw new Testing_Selenium_Exception('Curl returned non-null errno ' . $errno . ':' . curl_error($ch));
 
        }
 
        curl_close($ch);
 
        return $result;
 
    }
 
</code>
 
 
The $url here is the selenium server url.  curl_exc is calling that url.  Next to check is what selenium server does with getText as the verb in the $url.
 
 
==== getText docs? ====
 
look what I found: http://wiki.openqa.org/display/SEL/Selenium+Core+API+Documentation+Standard
 
<code>
 
Selenium.prototype.getText = function(locator) {
 
  /**
 
    * Get the (trimmed) text of a <i>form</i> element.
 
    * @param locator an element locator specifying the element whose text
 
    *  we'll extract
 
    * @return string the (trimmed) text of the element
 
    */
 
  var element = this.page().findElement(locator);
 
  return getText(element).trim();
 
};</code>
 
and
 
 
getText, which is defined as follows in selenium-api.js:
 
 
<code>
 
Selenium.prototype.getText = function(locator) {
 
var element = this.page().findElement(locator);
 
return getText(element).trim();
 
};</code>
 
 
yep, line 1154 in selenium-api.js [http://svn.openqa.org/fisheye/browse/selenium/trunk/code/javascript/core/scripts/selenium-api.js?r=1732]
 
<code>
 
Selenium.prototype.getText = function(locator) {
 
    /**
 
  * Gets the text of an element. This works for any element that contains
 
  * text. This command uses either the textContent (Mozilla-like browsers) or
 
  * the innerText (IE-like browsers) of the element, which is the rendered
 
  * text shown to the user.
 
  *
 
  * @param locator an <a href="#locators">element locator</a>
 
  * @return string the text of the element
 
    */
 
  var element = this.browserbot.findElement(locator);
 
  return getText(element).trim();
 
};</code>
 
 
=== assertElementContainsText ===
 
<code>
 
    public function assertElementContainsText($locator, $text)
 
    {
 
        $this->assertContains($text, $this->getText($locator));
 
    }
 
</code>
 
 
=== /r/n, /r, & /n ===
 
Very strange. 
 
* Mediawiki doesn't care if I put /r or /n or /r/n into the wiki text, which is good, of course.
 
* If I put in /r/n or /r or /n and then change /r/n to /n and then /r to " " and /n to " " in my expected text, my tests pass as long as I don't have /r/r
 
* if I do have /r/r then that gets replaced in my expected test with two spaces, while in the getText output, there's only one space - I really need to look at docommand() to see why/how these end of line characters are being replaced/stripped
 
PHP '''does''' care which I use.
 
  
 
[[Category:Acceptance Tests]]
 
[[Category:Acceptance Tests]]

Revision as of 00:27, 25 March 2007

each test independent of the others? can we test preview or save if edit isn't working?

  • edit
    • logged in & not logged in, click the "edit" link at the top & "type" the "action=edit" url & click section edit & type section edit url
      • verify the textarea exists
      • verify the textarea contents are correct
      • verify that typing works
  • save
    • in edit mode, click the "Save page" button
    • verify that the page saves
      • we're now NOT in edit mode
      • the contents of the page are what we expect
  • preview
    • in edit mode, click the "Show preview" button
    • the page shows both the contents of the page in html AND the textarea we're editing

Next Actions

  • need to carefully think through edit tests to make sure they cannot pass when they shouldn't - all 8 tests now pass!
  • CFLN issue very interesting - I'm writing this $sectionOne="==first section==" .chr(13).chr(10). "test text in page $testPage $timestamp"; and then getting this from the test runner:
Failed asserting that 
<string:==first section== test text in page AboutUsTest.com 1173799512> 
contains "==first section==
test text in page AboutUsTest.com 1173799512".

Done

  • created files basic_wiki_functions_acceptance_test.sh & BasicWikiFunctionsTest.php
  • testEditLinkWholePageIP() & testEditLinkWholePageLogin() both call editLinkWholePage() which does the actual work - the only difference is the login one logs in
  • testEditLinkSectionIP() & testEditLinkSectionLogin() both call editLinkSection() - same as above
  • basic structure of the file is complete now with 8 tests in two categories, logged in & IP; calling 4 functions in two categories, whole page or section; calling 2 functions in two categories, edit link or type edit URL; call DoTest(), so it's something like this
    • doTest
      • editLink
        • editLinkWholePage
          • IP
          • logged in
        • editLinkSection
          • IP
          • logged in
      • editURL
        • editURLWholePage
          • IP
          • logged in
        • editURLSection
          • IP
          • logged in


Retrieved from "http://aboutus.com/index.php?title=Basic_Functions_of_a_Wiki&oldid=5740930"