사용자 도구

사이트 도구


wordpress:unit_testing

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
wordpress:unit_testing [2016/01/27 16:27] – [테스트 환경 만들기] changwoowordpress:unit_testing [2016/01/28 14:37] (현재) changwoo
줄 95: 줄 95:
 function _manually_load_plugin() { function _manually_load_plugin() {
  require dirname( dirname( __FILE__ ) ) . '/pluginTestSample.php';  require dirname( dirname( __FILE__ ) ) . '/pluginTestSample.php';
 +}
 +</code>
 +
 +
 +===== 워드프레스의 팩토리 =====
 +워드프레스 플러그인의 테스트는 ''WP_UnitTestCase'' 클래스를 확장하여 이뤄진다. 이 클래스는 팩토리 클래스를 제공한다. 이 팩토리 클래스를 이용하면, 워드프레스에서 관리하는 여러 오브젝트를 매우 편리하게 만들 수 있다.
 +
 +가령 포스트를 만드려면, 다음과 같이 코드를 작성한다.
 +<code php>
 +$post_id = $this->factory->post->create( array( 'post_title' => 'Test Post' );
 +</code>
 +
 +여러 레코드를 생성하는 것도 가능하다
 +<code php>
 +$post_ids = $this->factory->post->create_many( 10 );
 +</code>
 +
 +기본적으로 제공하는 팩토리는 다음과 같다.
 +<code php>
 +$this->post = new WP_UnitTest_Factory_For_Post( $this );
 +$this->attachment = new WP_UnitTest_Factory_For_Attachment( $this );
 +$this->comment = new WP_UnitTest_Factory_For_Comment( $this );
 +$this->user = new WP_UnitTest_Factory_For_User( $this );
 +$this->term = new WP_UnitTest_Factory_For_Term( $this );
 +$this->category = new WP_UnitTest_Factory_For_Term( $this, 'category' );
 +$this->tag = new WP_UnitTest_Factory_For_Term( $this, 'post_tag' );
 +if ( is_multisite() ) {
 + $this->blog = new WP_UnitTest_Factory_For_Blog( $this );
 + $this->network = new WP_UnitTest_Factory_For_Network( $this );
 } }
 </code> </code>
wordpress/unit_testing.1453912024.txt.gz · 마지막으로 수정됨: 2016/01/27 16:27 저자 changwoo

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki