public function test_release_rejected_when_new_version_is_less_than_latest()
 {
     $product = $this->product_factory->create_and_get();
     $file1 = $this->factory->attachment->create_object('file.zip', $product->ID, array('post_mime_type' => 'application/zip'));
     /** @var Release $r1 */
     $r1 = $this->release_factory->create_and_get(array('product' => $product->ID, 'file' => $file1, 'version' => '1.0', 'type' => Release::TYPE_MAJOR));
     update_post_meta($product->ID, '_itelic_first_release', $r1->get_pk());
     $file2 = $this->factory->attachment->create_object('file2.zip', $product->ID, array('post_mime_type' => 'application/zip'));
     $this->setExpectedException('\\InvalidArgumentException');
     Release::create($product, get_post($file2), '0.9', Release::TYPE_MAJOR);
 }
Пример #2
0
/**
 * Create a release.
 *
 * @api
 *
 * @since 1.0
 *
 * @param array $args
 *
 * @return \ITELIC\Release|WP_Error
 */
function itelic_create_release($args)
{
    $defaults = array('product' => '', 'file' => '', 'version' => '', 'type' => '', 'status' => '', 'changelog' => '');
    $args = wp_parse_args($args, $defaults);
    if (is_numeric($args['product'])) {
        $product = itelic_get_product($args['product']);
    } else {
        $product = $args['product'];
    }
    if (!$product) {
        return new WP_Error('invalid_product', __('Invalid Product', \ITELIC\Plugin::SLUG));
    }
    if (is_numeric($args['file'])) {
        $file = get_post($args['file']);
    } else {
        $file = $args['file'];
    }
    if (!$file || get_post_type($file) != 'attachment') {
        return new WP_Error('invalid_file', __("Invalid File", \ITELIC\Plugin::SLUG));
    }
    $version = $args['version'];
    $type = $args['type'];
    $status = $args['status'];
    $changelog = $args['changelog'];
    try {
        $release = \ITELIC\Release::create($product, $file, $version, $type, $status, $changelog);
        if (isset($args['security-message'])) {
            $release->add_meta('security-message', $args['security-message']);
        }
        return $release;
    } catch (InvalidArgumentException $e) {
        return new WP_Error('exception', $e->getMessage());
    }
}