public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_term_by', ['times' => '2', 'return' => (object) $mockTerms['catTerm1']]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $t = new Commands\Taxonomies();
     $t->add(array('category', 21), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'catTerm1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', '*'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('*', $settings['content']['taxonomies']['category'][0]);
     \WP_Mock::wpFunction('get_term_by', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'yadayada'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['taxonomies']['category']));
 }
 public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $m = new Commands\Menus();
     $cli = $app['cli'];
     $cli->launch_self_return = (object) ['return_code' => 0, 'stdout' => json_encode([(object) ['term_id' => 1, 'name' => 'Main menu', 'slug' => 'main', 'locations' => ['primary', 'footer'], 'count' => 2]])];
     $m->add(array('main'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(1), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(999), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['menus']));
 }
 public function testAdd()
 {
     global $testHelpers, $mockPosts;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_post', ['times' => '1', 'return' => (object) $mockPosts['testpost1']]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => [(object) $mockPosts['testpost1']]]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $cli = $app['cli'];
     $p = new Commands\Posts();
     $p->add(array(10), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['posts']['post']));
 }
 public function testCreate()
 {
     global $testHelpers;
     $testHelpers->removeSettings();
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $app = Bootstrap::getApplication();
     $bootstrap = new Bootstrap();
 }
예제 #5
0
 public function testFindTargetObjectId()
 {
     global $testHelpers;
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $app = Bootstrap::getApplication();
     $import = $app['import'];
     $testHelpers->makePublic($import, 'posts');
     $testHelpers->makePublic($import, 'taxonomies');
     $import->taxonomies = ['category' => (object) ['terms' => [(object) ['id' => 20, 'term' => ['term_id' => 98]]]]];
     $this->assertEquals(20, $import->findTargetObjectId(98, 'term'));
     $this->assertEquals(0, $import->findTargetObjectId(999, 'term'));
     $import->posts = [(object) ['id' => 10, 'post' => ['ID' => 12]]];
     $this->assertEquals(10, $import->findTargetObjectId(12, 'post'));
     $this->assertEquals(0, $import->findTargetObjectId(999, 'post'));
 }
 public function testShow()
 {
     global $testHelpers;
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $snapper = new OptionSnap();
     $snapper->show(['snapWrong'], []);
     $cli = $app['cli'];
     $this->assertTrue(count($cli->error) == 1);
     $snapper->show(['snap1'], []);
     $utils = $app['cliutils'];
     $this->assertTrue(count($utils->output) == 2);
     $this->assertTrue($utils->output[0]['name'] == 'opta');
     $snapper->show(['snap1', 'optb'], []);
     $snapper->show(['snap1', 'optb'], []);
     $cli = $app['cli'];
     $this->assertTrue(count($cli->line) == 2);
 }
예제 #7
0
 private function runExport()
 {
     global $testHelpers;
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $helpers = $app['helpers'];
     $helpers->recursiveRemoveDirectory(WPBOOT_BASEPATH . '/bootstrap');
     require_once WPBOOT_BASEPATH . '/www/wordpress-test/wp-load.php';
     $export = $app['export'];
     $export->run([], []);
 }