2017-01-20 7 views
1

$string(f.e. 123)は、特定のHTML要素内でのみ発生しますが、PHP/Codeception受け入れテストを使用して外部や他の場所では発生しないことを確認するにはどうすればよいですか?PHPでソースコードのシングルオカレンスを確認するコード受入れテスト

微細なり例:#1(テキスト発生)を失敗し

<html><body>foobar 234<div id="original">123</div></body></html> 

例:

<html><body>foobar 123<div id="original">123</div></body></html> 

例#2(リンクの発生)を失敗する:

<html> 
    <body> 
    foobar 
    <div id="original">123</div> 
    <a href="/link/123">Link</a> 
    </body> 
</html> 

特定のページ以外のテストで試したこと:

$I->seeInPageSource($alias); 
$I->dontSeeInPageSource($original); 

今私は

$I->seeInPageSourceElement($original, '#original'); 

$I->dontSeeInPageSourceExceptElement($original, '#original'); 
// could be implemented like this: 
$pageSourceWithoutElement = str_replace(
    $I->grabPageSourceElement('#original'), 
    '', 
    $I->grabPageSource() 
); 
$I->assertNotContains($original, $pageSourceWithoutElement); 

理由のようなものが必要になります 私は2つのバージョンを持って、1つのバージョン(「オリジナル」と呼ばれる)、別のエイリアスがどこにありますか。エイリアスの定義が表示されている「オリジナル表示」ページ以外では、エイリアスのみがどこでも使用されていることを確認したいと思います。

答えて

0

私は解決策が見つかりました:

  • jQueryを使って切り離し要素(それを使用するためにテストページを要求する)
  • 定期的なテストを行う
  • 再取り付け要素

ない完璧を解決策ですが、機能します。

public function dontSeeInPageSourceExceptElement($text, $excludeSelector) 
    { 
     $I = $this; 

     // check for positive occurrence in exclude selector (optional) 
     // $I->see($text, $excludeSelector); 

     // detach the selected element 
     // Problem: append() just re-attaches the element, but this might not be the right position 
     $I->executeJs(
      sprintf(
       // s = subject, p = parent, bs = backup of subject 
       "var s = $(%s), p = s.parent(), bs = s.detach(); " . 
       "setTimeout(function() { p.append(bs); }, 2000);", 
       json_encode($excludeSelector) 
      ) 
     ); 

     // check for negative occurrence now 
     $I->dontSeeInPageSource($text); 

     // wait 2 seconds (re-attach timeout) 
     $I->wait(2); 
    } 
関連する問題