Skip to content

test: Add tests for php and ruby #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/duplication-tests/php-no-results/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<checkstyle version="4.3" />
9 changes: 9 additions & 0 deletions docs/duplication-tests/php-no-results/src/NoResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class NoResults
{
public function test()
{

}
}
23 changes: 23 additions & 0 deletions docs/duplication-tests/php-with-results/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<checkstyle version="4.3">
<property name="ignoreMessage" />
<duplication nrTokens="92" nrLines="23" message="">
<file name="Selenium2.php">
<property name="startLine" value="68" />
<property name="endLine" value="91" />
</file>
<file name="Selenium.php">
<property name="startLine" value="107" />
<property name="endLine" value="130" />
</file>
</duplication>
<duplication nrTokens="113" nrLines="27" message="">
<file name="Selenium2.php">
<property name="startLine" value="131" />
<property name="endLine" value="158" />
</file>
<file name="Selenium.php">
<property name="startLine" value="69" />
<property name="endLine" value="96" />
</file>
</duplication>
</checkstyle>
134 changes: 134 additions & 0 deletions docs/duplication-tests/php-with-results/src/Selenium.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <[email protected]>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <[email protected]>
* @author Shin Ohno <[email protected]>
* @author Giorgio Sironi <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/

/**
* Tests for PHPUnit_Extensions_SeleniumTestCase.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <[email protected]>
* @author Shin Ohno <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_SeleniumTestCaseTest extends Tests_SeleniumTestCase_BaseTestCase
{
public function testOpen()
{
$this->open('html/test_open.html');
$this->assertStringEndsWith('html/test_open.html', $this->getLocation());
$this->assertEquals('This is a test of the open command.', $this->getBodyText());

$this->open('html/test_page.slow.html');
$this->assertStringEndsWith('html/test_page.slow.html', $this->getLocation());
$this->assertEquals('Slow Loading Page', $this->getTitle());
}

public function testClick()
{
$this->open('html/test_click_page1.html');
$this->assertEquals('Click here for next page', $this->getText('link'));
$this->click('link');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page 1', $this->getTitle());

$this->click('linkWithEnclosedImage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);

$this->click('enclosedImage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);

$this->click('linkToAnchorOnThisPage');
$this->assertEquals('Click Page 1', $this->getTitle());
$this->click('linkWithOnclickReturnsFalse');
$this->assertEquals('Click Page 1', $this->getTitle());

}

public function testClickJavaScriptHref()
{
$this->open('html/test_click_javascript_page.html');
$this->click('link');
$this->assertEquals('link clicked', $this->getText('result'));
}


public function testStaleElementsCannotBeAccessed()
{
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$div = $this->byId('theDivId');
$div = $this->byId('theDivId');
$div = $this->byId('theDivId');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
try {
$div->text();
$div->text();
$div->text();
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
} catch (RuntimeException $e) {
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
}
}

}

160 changes: 160 additions & 0 deletions docs/duplication-tests/php-with-results/src/Selenium2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <[email protected]>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/

use PHPUnit_Extensions_Selenium2TestCase_Keys as Keys;

/**
* Tests for PHPUnit_Extensions_Selenium2TestCase.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCaseTest extends Tests_Selenium2TestCase_BaseTestCase
{
public function testOpen()
{
$this->open('html/test_open.html');
$this->assertStringEndsWith('html/test_open.html', $this->getLocation());
$this->assertEquals('This is a test of the open command.', $this->getBodyText());

$this->open('html/test_page.slow.html');
$this->assertStringEndsWith('html/test_page.slow.html', $this->getLocation());
$this->assertEquals('Slow Loading Page', $this->getTitle());
}

public function testStaleElementsCannotBeAccessed()
{
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
$div = $this->byId('theDivId');
$div = $this->byId('theDivId');
$div = $this->byId('theDivId');
$this->url('html/test_element_selection.html');
$this->url('html/test_element_selection.html');
try {
$div->text();
$div->text();
$div->text();
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
$this->fail('The element shouldn\'t be accessible.');
} catch (RuntimeException $e) {
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
}
}

public function testVersionCanBeReadFromTheTestCaseClass()
{
$this->assertEquals(1, version_compare(PHPUnit_Extensions_Selenium2TestCase::VERSION, "1.2.0"));
}

public function testCamelCaseUrlsAreSupported()
{
$this->url('html/CamelCasePage.html');
$this->assertStringEndsWith('html/CamelCasePage.html', $this->url());
$this->assertEquals('CamelCase page', $this->title());
}

public function testAbsoluteUrlsAreSupported()
{
$this->url(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL . 'html/test_open.html');
$this->assertEquals('Test open', $this->title());
}

public function testElementSelection()
{
$this->url('html/test_open.html');
$element = $this->byCssSelector('body');
$this->assertEquals('This is a test of the open command.', $element->text());

$this->url('html/test_click_page1.html');
$link = $this->byId('link');
$this->assertEquals('Click here for next page', $link->text());
}

public function testMultipleElementsSelection()
{
$this->url('html/test_element_selection.html');
$elements = $this->elements($this->using('css selector')->value('div'));
$this->assertEquals(4, count($elements));
$this->assertEquals('Other div', $elements[0]->text());
}

public function testClick()
{
$this->open('html/test_click_page1.html');
$this->assertEquals('Click here for next page', $this->getText('link'));
$this->click('link');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page 1', $this->getTitle());

$this->click('linkWithEnclosedImage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);

$this->click('enclosedImage');
$this->waitForPageToLoad(500);
$this->assertEquals('Click Page Target', $this->getTitle());
$this->click('previousPage');
$this->waitForPageToLoad(500);

$this->click('linkToAnchorOnThisPage');
$this->assertEquals('Click Page 1', $this->getTitle());
$this->click('linkWithOnclickReturnsFalse');
$this->assertEquals('Click Page 1', $this->getTitle());

}
}
32 changes: 32 additions & 0 deletions docs/duplication-tests/ruby-contain-results/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<checkstyle version="4.3">
<duplication nrTokens="10" nrLines="2" message="msg = &quot;sexp_to_#{File.extname(node.file).sub(/./, &quot;&quot;)}&quot;&#10;self.respond_to?(msg) ? (self.send(msg, node)) : (sexp_to_rb(node))&#10;msg = &quot;sexp_to_#{File.extname(s.file).sub(/./, &quot;&quot;)}&quot;&#10;self.respond_to?(msg) ? (self.send(msg, s)) : (sexp_to_rb(s))">
<file name="flay.rb">
<property name="startLine" value="549"></property>
<property name="endLine" value="550"></property>
</file>
<file name="flay.rb">
<property name="startLine" value="607"></property>
<property name="endLine" value="608"></property>
</file>
</duplication>
<duplication nrTokens="10" nrLines="3" message="opts.on(&quot;-m&quot;, &quot;--mass MASS&quot;, Integer, &quot;Sets mass threshold (default = #{options[:mass]})&quot;) do |m|&#10; options[:mass] = m.to_i&#10;end&#10;opts.on(&quot;-t&quot;, &quot;--timeout TIME&quot;, Integer, &quot;Set the timeout. (default = #{options[:timeout]})&quot;) do |t|&#10; options[:timeout] = t.to_i&#10;end">
<file name="flay.rb">
<property name="startLine" value="76"></property>
<property name="endLine" value="78"></property>
</file>
<file name="flay.rb">
<property name="startLine" value="101"></property>
<property name="endLine" value="103"></property>
</file>
</duplication>
<duplication nrTokens="10" nrLines="7" message="def add_expr_literal(src, code)&#10; if code.=~(BLOCK_EXPR) then&#10; ((src &lt;&lt; &quot;@output_buffer.append= &quot;) &lt;&lt; code)&#10; else&#10; (((src &lt;&lt; &quot;@output_buffer.append=(&quot;) &lt;&lt; code) &lt;&lt; &quot;);&quot;)&#10; end&#10;end&#10;def add_expr_escaped(src, code)&#10; if code.=~(BLOCK_EXPR) then&#10; ((src &lt;&lt; &quot;@output_buffer.safe_append= &quot;) &lt;&lt; code)&#10; else&#10; (((src &lt;&lt; &quot;@output_buffer.safe_append=(&quot;) &lt;&lt; code) &lt;&lt; &quot;);&quot;)&#10; end&#10;end">
<file name="flay_erb.rb">
<property name="startLine" value="28"></property>
<property name="endLine" value="34"></property>
</file>
<file name="flay_erb.rb">
<property name="startLine" value="36"></property>
<property name="endLine" value="42"></property>
</file>
</duplication>
</checkstyle>
Loading