Upgrade to Pro — share decks privately, control downloads, hide ads and more …

wpceptを使おう

Ippei Sumida
September 19, 2016

 wpceptを使おう

WordBench京都9月で発表したスライドです。

Ippei Sumida

September 19, 2016
Tweet

More Decks by Ippei Sumida

Other Decks in Programming

Transcript

  1. Codeception • PHPͰಈ࡞͢ΔςεςΟϯάϑϨʔϜϫʔΫ • Unit - PHPUnitςετ • Functional -

    ػೳςετ • Acceptance - ड͚ೖΕςετɹˡϒϥ΢βςετ • CIͱ࿈ܞՄʂ
  2. Acceptance Test • PHPBrowser - PHPͰಈ࡞͢Δ؆қϒϥ΢βɻ JavaScript͕࢖͑ͳ͍ɻ • Phantom.js -

    JSͰಈ࡞͢Δϒϥ΢βɻBasicೝূ͕࢖͑ ͳ͍ɻ • WebDriver - ֤छϒϥ΢βΛར༻͢ΔυϥΠόɻσϑΥ ϧτ͸Firefox
  3. How to write AcceptanceTest /** * ςετϝιου * @param AcceptanceTester

    $I */ public function tryToTest(AcceptanceTester $I) { $this->_notTest($I); }
  4. How to execute AcceptanceTest vendor/bin/codecept build # શ࣮ߦ vendor/bin/codecept run

    acceptance # ࢦఆϑΝΠϧ͚࣮ͩߦ vendor/bin/codecept run acceptance IndexCest
  5. Acceptance Test • WPBrowser - PHPͰಈ࡞͢Δ؆қϒϥ΢βɻJavaScript ͕࢖͑ͳ͍ɻ • WPWebDriver(Phantom.js) -

    JSͰಈ࡞͢Δϒϥ΢βɻ Basicೝূ͕࢖͑ͳ͍ɻ • WPWebDriver(Selenium) - ֤छϒϥ΢βΛར༻͢Δυ ϥΠόɻσϑΥϧτ͸Firefox
  6. How to configure wpcept # Codeception Test Suite Configuration #

    Suite for WordPress acceptance tests. # Perform tests using or simulating a browser. class_name: AcceptanceTester modules: enabled: - \Helper\Acceptance - WPBrowser: url: 'http://wb-kyoto-201609.local' adminUsername: admin adminPassword: adminp adminPath: /wp-admin acceptance.suite.yml
  7. How to configure wpcept class_name: AcceptanceTester modules: enabled: - \Helper\Acceptance

    - WPWebDriver config: WPWebDriver: url: 'http://wb-kyoto-201609.local' browser: 'firefox' window_size: '1024x768' adminUsername: admin adminPassword: adminp adminPath: /wp-admin acceptance.suite.yml
  8. How to configure wpcept env: wpbrowser: modules: enabled: - WPBrowser

    disabled: - WPWebDriver config: WPBrowser: url: 'http://wb-kyoto-201609.local' adminUsername: admin adminPassword: adminp adminPath: /wp-admin chrome: modules: config: WPWebDriver: browser: 'chrome' acceptance.suite.yml
  9. How to execute wpcept vendor/bin/wpcept build # શ࣮ߦ vendor/bin/wpcept run

    acceptance # ࢦఆϑΝΠϧ͚࣮ͩߦ vendor/bin/wpcept run acceptance IndexCest # ؀ڥΛࢦఆ࣮ͯ͠ߦ vendor/bin/wpcept run acceptance —env=chrome
  10. Commonly Used methods ϝιου උߟ ࢦఆͷϖʔδʹҠಈ *BN0O1BHF l63-z  BDDFQUBODFTVJUFZNMʹࢦఆ

    ͨ͠63-ʹ௥Ճ͞ΕͯΞΫη εɻ ϖʔδʹࢦఆͷจࣈ͕͋Δ͔ *TFF lจࣈྻz  *TFF lจࣈྻz lཁૉz  *DBO4FF lจࣈྻz  DBOΛ͚ͭΔͱݟ͔ͭΒͳ͘ ͯ΋ςετ͕ࢭ·Βͳ͍ ϖʔδʹࢦఆͷจࣈ͕ͳ͍͔ *EPOU4FF lจࣈྻz  *EPOU4FF lจࣈྻz lཁ ૉz  *DBOU4FF lจࣈྻz  DBOΛ͚ͭΔͱݟ͔ͭΒͳ͘ ͯ΋ςετ͕ࢭ·Βͳ͍ ΫϦοΫ *DMJDL lϩάΠϯz  *DMJDL lMPHJOz  จࣈྻ 9QBUI $444FMFDUPS Ͱࢦఆ
  11. ϝιου උߟ ςΩετϘοΫεʹॻ͘ *pMM'JFME lOBNFz lWBMVFz  *pMM'JFME lOBNFz 

    lWBMVFz  ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ ϥδΦϘλϯબ୒ *DIFDL0QUJPO lOBNFz  lWBMVFz  *DIFDL0QUJPO lOBNFz  lWBMVFz  ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ ηϨΫτϘοΫεɺνΣοΫ ϘοΫεબ୒ *TFMFDU0QUJPO lOBNFz  lWBMVFz  *TFMFDU0QUJPO lOBNFz  lWBMVFz  ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ Commonly Used methods
  12. ϝιου උߟ ؅ཧϢʔβϩάΠϯ͢Δ *MPHJO"T"ENJO  *% 18͸ઃఆϑΝΠϧʹ ϓϥάΠϯҰཡϖʔδ΁ *BN0O1MVHJOT1BHF 

    ϓϥάΠϯ༗ޮԽ * BDUJWBUF1MVHJO bQMVHJO4MVH` ϝιουલʹ BN0O1MVHJOT1BHF ΛݺͿ ϓϥάΠϯແޮԽ * EF"DUJWBUF1MVHJO bQMVHJO4M VH`  ϝιουલʹ BN0O1MVHJOT1BHF ΛݺͿ ඞཁ͋Γ Commonly Used methods
  13. How to write test case public function indexWithLoginTest(AcceptanceTester $I)
 {


    $I->wantToTest('ϩάΠϯͯ͠Δͱ͖ͷTOPςετ');
 $I->loginAsAdmin();
 $I->amOnPage("/");
 // αΠτͷͲ͔͜ʹ֘౰ͷจࣈྻ͕͋Δ͔֬ೝ
 $I->canSee("wb-kyoto-201609");
 // CSS SelectorͰࢦఆͯ֘͠౰ͷจࣈྻ͕͋Δ͔֬ೝ
 $I->canSee('Just another WordPress site', '#masthead > div > div > p');
 // XPathͰࢦఆͯ֘͠౰ͷจࣈྻ͕͋Δ͔֬ೝ
 $I->canSee('͜Μʹͪ͸ɺadmin ͞Μ !', '//*[@id="wp-admin-bar- my-account"]/a');
 }

  14. XPath XML Path Language ʢXPathʢΤοΫεύεʣʣ ͸ɺϚʔΫΞοϓݴޠ XML ʹ४ڌͨ͠จॻͷಛఆͷ෦෼Λࢦఆ͢Δݴޠߏจ Ͱ͋Δɻ XPathࣗମ͸؆ܿͳߏจ

    ʢࣜݴޠʣ Ͱ͋ΓɺXMLʹ४ڌͨ͠ϚʔΫΞοϓݴޠͰ͸ͳ͍ɻ ඪ४Խஂମ W3C (World Wide Web Consortium) Ͱ։ൃ͞Εɺ1999೥11݄16೔ʹ XML Path Language (XPath) 1.0 ͕ XSL Transformations (XSLT) 1.0 ͱ ಉ࣌ʹקࠂͱͯ͠ެද͞Εͨ[1][2]ɻ XPath͸ɺXSLT ͱ XSL-FO ͱͱ΋ʹελΠϧγʔτٕज़ XSL ͷߏ੒ཁૉͱҐஔ͚ͮΒΕͯ ͍Δɻ 2007೥1݄23೔ɺW3C Ͱ XPath 1.0 ͷ࣍ظόʔδϣϯ੍͕ఆ͞ΕɺXPath 2.0 ͕ XSLT 2.0 ͱಉ࣌ʹקࠂ͞Εͨɻ ·ͨ W3C ͸ XPath 2.0 Λ֦ுٕͨ͠ज़ͱͯ͠ XQuery 1.0 Λ։ൃ͠ɺ2007೥1݄23೔ͷ XPath 2.0 / XSLT 2.0 ͷקࠂͱಉ࣌ʹ XQuery 1.0 ͕קࠂ͞Εͨɻ2014೥4݄8೔ʹ XPath 3.0 ͕קࠂ͞Εͨɻ XPath 1.0 ͕ެද͞ΕΔͱɺXMLจॻʹର͢Δ؆୯ͳ໰͍߹Θͤݴޠͱͯ͠ɺٸ଎ʹXMLΛѻ͏ιϑτ΢ΣΞ։ൃऀ ʢϓϩάϥ Ϛʣ ͨͪʹड͚ೖΕΒΕ͍ͯͬͨɻ ΋ͱ΋ͱ͸XPathͷ։ൃ͸ɺXSL (XSLT) ͱ XPointer ʹڞ௨͢ΔߏจͱৼΔ෣͍ͷϞσϧΛ ։ൃ͢Δ͜ͱΛ໨ඪͱ͍ͯͨ͠ɻ ࣮ࡍʹXSLTͰ͸ɺXMLจॻͷಛఆͷ෦෼Λࢦఆ͢ΔύλʔϯΛɺXPathΛجʹͨ͠ߏจͰࢦఆ ͢Δɻ ҰൠʹXSLTॲཧܥͷ࣮૷͸ɺXPathॲཧܥͷ࣮૷ΛؚΜͰ͍Δɻ XPath 1.0͸2007೥ʹ຋༁͞ΕJIS X 4160ͱͯ͠JISن֨Խ͞Ε͍ͯΔɻ
 
 ˞WikipediaΑΓ
  15. Get XPath <div id="page" class="site"> <div class="site-inner"> <a class="skip-link screen-reader-text"

    href=“#content”> ίϯςϯπ΁εΩοϓ</a> ←͜͜͸ //*[@id="page"]/div/a
  16. Get XPath? <section id="meta-2" class="widget widget_meta"><h2 class="widget-title">ϝλ৘ใ</ h2> <ul> <li><a

    href=“http://wb-kyoto-201609.local/wp-admin/">αΠτ؅ཧ</a></li> <li><a href="http://wb-kyoto-201609.local/wp-login.php? action=logout&#038;_wpnonce=c3c4a7821f">ϩάΞ΢τ</a></li> <li><a href="http://wb-kyoto-201609.local/feed/">౤ߘͷ <abbr title="Really Simple Syndication”>RSS←͜͜͸ʁ</abbr></a></li> <li><a href="http://wb-kyoto-201609.local/comments/feed/">ίϝϯτͷ <abbr title="Really Simple Syndication">RSS</abbr></a></li> <li><a href="https://ja.wordpress.org/" title="Powered by WordPress, state- of-the-art semantic personal publishing platform.">WordPress.org</a></li> </ul> </section> ??? ※ෳࡶͳHTMLʹͳΔͱେม